Class: Juknife::Scraping::Runner
- Inherits:
-
Object
- Object
- Juknife::Scraping::Runner
- Includes:
- DSL
- Defined in:
- lib/juknife/scraping/runner.rb
Overview
Juknife::Scraping::Runner object is a runner for scraping DSL.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #document ⇒ Object
-
#initialize(&block) ⇒ Runner
constructor
A new instance of Runner.
- #result ⇒ Object
- #run(source, params = {}) ⇒ Object
Methods included from DSL
#children, #item, #items, #scope
Constructor Details
#initialize(&block) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 |
# File 'lib/juknife/scraping/runner.rb', line 12 def initialize(&block) @block = block instance_eval(&@block) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
10 11 12 |
# File 'lib/juknife/scraping/runner.rb', line 10 def block @block end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/juknife/scraping/runner.rb', line 10 def params @params end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/juknife/scraping/runner.rb', line 10 def source @source end |
Instance Method Details
#document ⇒ Object
23 24 25 |
# File 'lib/juknife/scraping/runner.rb', line 23 def document @document ||= Nokogiri.parse(source) end |
#result ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/juknife/scraping/runner.rb', line 27 def result context = Scraping::Context.new(document) children.each do |child| child.visit(context) end context.result end |
#run(source, params = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/juknife/scraping/runner.rb', line 17 def run(source, params = {}) @params = params @source = source result end |