Class: ScrapedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/web-scraper/scraped_response.rb

Overview

ScrapedResponse

Will hold values from the scraping of the page

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_content, options) ⇒ ScrapedResponse

The constructor define at runtime all the methods name contained in the key of the hash that will return the computation of the XPath of the hash value



10
11
12
13
14
# File 'lib/web-scraper/scraped_response.rb', line 10

def initialize(page_content, options)     
  # puts page_content
  @document = Nokogiri::HTML(page_content)    
  ScrapedResponse.create_methods(options)
end

Class Method Details

.create_methods(options) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/web-scraper/scraped_response.rb', line 16

def self.create_methods(options)    
  options.each do |key,value|      
    define_method(key) do
      @document.xpath(value).children.first.text.strip!
    end            
  end        
end