Class: Scraprr::Scraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_scraperObject (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_pathObject (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