Class: Scraprr::ObjectScraper
- Inherits:
-
Object
- Object
- Scraprr::ObjectScraper
- Defined in:
- lib/scraprr/object_scraper.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #attribute(name, path = AttributeScraper::DEFAULT_PATH, opts = {}) ⇒ Object
- #extract(node) ⇒ Object
-
#initialize ⇒ ObjectScraper
constructor
A new instance of ObjectScraper.
Constructor Details
#initialize ⇒ ObjectScraper
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
#attributes ⇒ Object (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 |