I am trying to scrape an xml website and get contents from it.
class PageScraper
def get_page_details
if xml_data
#get the info from xml website
else
#get it from html website
end
end
def get_xml_details
if xml_data
#get it from xml website
end
end
def xml_data
xml_url = www.abcd.xml
#Download and parse the xml data from abcd.xml site using nokogiri-gem
end
end
Here, there are other methods which need to get the xml_data method. Every time, it needs to go and fetch and download data from xml website.
Is there any way to store the xml data in a variable (like @data = xml_data()) first time it is called and return the downloaded xml_data? In the next subsequent call to xml_data, it should be able to refer @data, which is cached.