Class: AmazonDeets::MechanizedScraper

Inherits:
AbstractScraper show all
Defined in:
lib/amazon_deets/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent: Mechanize.new, fragments: Array.new) ⇒ MechanizedScraper

Returns a new instance of MechanizedScraper.



25
26
27
28
# File 'lib/amazon_deets/core.rb', line 25

def initialize(agent: Mechanize.new, fragments: Array.new)
  @agent     = agent
  @fragments = fragments
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



22
23
24
# File 'lib/amazon_deets/core.rb', line 22

def agent
  @agent
end

#fragmentsObject

Returns the value of attribute fragments.



23
24
25
# File 'lib/amazon_deets/core.rb', line 23

def fragments
  @fragments
end

Instance Method Details

#scrape(url) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/amazon_deets/core.rb', line 30

def scrape(url)
  agent.get(url)
  fragments.each do |f|
    if f.applicable?(agent)
      return f.scrape(agent)
    end
  end
end