class NlGasStations::Scraper
Public Class Methods
scrape(params)
click to toggle source
Read the data from the source website and parse it. If a cache is configured, a cached value will be returned.
# File lib/nl_gas_stations/scraper.rb, line 15 def self.scrape(params) url = ROOT_URL + '?' + params.to_query if NlGasStations.configuration.cache.nil? html = make_request(url) parse(html) else NlGasStations.configuration.cache.fetch(NlGasStations.configuration.cache_prefix + params.to_query, expires_in: NlGasStations.configuration.cache_expires_in) do html = make_request(url) parse(html) end end end
Private Class Methods
make_request(url)
click to toggle source
Make a request and return the Nokogiri::HTML object.
# File lib/nl_gas_stations/scraper.rb, line 34 def self.make_request(url) response = open(url) Nokogiri::HTML(response) end
parse(html)
click to toggle source
Parse the Nokogiri::HTML object with the Parser cals
# File lib/nl_gas_stations/scraper.rb, line 41 def self.parse(html) parser = Parser.new(html) parser.parse end