Class: Juknife::Scraper

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

Overview

Juknife::Scraper is a scraper to request a web page and to extract data.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScraper

Returns a new instance of Scraper.


6
7
8
9
# File 'lib/juknife/scraper.rb', line 6

def initialize
  @scraping = Scraping::Runner.new(&self.class.scraping_block)
  @request = Request::Runner.new(&self.class.request_block)
end

Class Attribute Details

.request_blockObject (readonly)

Returns the value of attribute request_block


17
18
19
# File 'lib/juknife/scraper.rb', line 17

def request_block
  @request_block
end

.scraping_blockObject (readonly)

Returns the value of attribute scraping_block


17
18
19
# File 'lib/juknife/scraper.rb', line 17

def scraping_block
  @scraping_block
end

Class Method Details

.request(&block) ⇒ Object


23
24
25
# File 'lib/juknife/scraper.rb', line 23

def request(&block)
  @request_block = block
end

.scraping(&block) ⇒ Object


19
20
21
# File 'lib/juknife/scraper.rb', line 19

def scraping(&block)
  @scraping_block = block
end

Instance Method Details

#scrape(params = {}) ⇒ Object


11
12
13
14
# File 'lib/juknife/scraper.rb', line 11

def scrape(params = {})
  source = @request.run(params)
  @scraping.run(source, params)
end