Class: Scraprr::Scraper
- Inherits:
-
Object
- Object
- Scraprr::Scraper
- Defined in:
- lib/scraprr/scraper.rb
Instance Attribute Summary collapse
-
#object_scraper ⇒ Object
readonly
Returns the value of attribute object_scraper.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Instance Method Summary collapse
- #attribute(name, path = AttributeScraper::DEFAULT_PATH, opts = {}) ⇒ Object
- #extract(document) ⇒ Object
-
#initialize(root_path = '/') ⇒ Scraper
constructor
A new instance of Scraper.
- #root(path) ⇒ Object
Constructor Details
#initialize(root_path = '/') ⇒ Scraper
Returns a new instance of Scraper.
5 6 7 8 |
# File 'lib/scraprr/scraper.rb', line 5 def initialize(root_path = '/') @root_path = root_path @object_scraper = ObjectScraper.new end |
Instance Attribute Details
#object_scraper ⇒ Object (readonly)
Returns the value of attribute object_scraper.
3 4 5 |
# File 'lib/scraprr/scraper.rb', line 3 def object_scraper @object_scraper end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
3 4 5 |
# File 'lib/scraprr/scraper.rb', line 3 def root_path @root_path end |
Instance Method Details
#attribute(name, path = AttributeScraper::DEFAULT_PATH, opts = {}) ⇒ Object
15 16 17 18 |
# File 'lib/scraprr/scraper.rb', line 15 def attribute(name, path = AttributeScraper::DEFAULT_PATH, opts = {}) @object_scraper.attribute(name, path, opts) self end |
#extract(document) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/scraprr/scraper.rb', line 20 def extract(document) items = [] document.search(root_path).each do |node| extract_item_into(items, node) end items end |
#root(path) ⇒ Object
10 11 12 13 |
# File 'lib/scraprr/scraper.rb', line 10 def root(path) @root_path = path self end |