Class: Scraprr::ObjectScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/scraprr/object_scraper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObjectScraper

Returns a new instance of ObjectScraper.



5
6
7
# File 'lib/scraprr/object_scraper.rb', line 5

def initialize
  @attributes = Set.new
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/scraprr/object_scraper.rb', line 3

def attributes
  @attributes
end

Instance Method Details

#attribute(name, path = AttributeScraper::DEFAULT_PATH, opts = {}) ⇒ Object



9
10
11
12
# File 'lib/scraprr/object_scraper.rb', line 9

def attribute(name, path=AttributeScraper::DEFAULT_PATH, opts={})
  @attributes.add(AttributeScraper.new(name, path, opts))
  self
end

#extract(node) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/scraprr/object_scraper.rb', line 14

def extract(node)
  attributes.reduce({}) do |item, attribute_scraper|
    element = node.search(attribute_scraper.path)
    item[attribute_scraper.name] = attribute_scraper.extract(element)
    item
  end
end