Class: EagleClaw::Scraper
- Inherits:
-
Object
- Object
- EagleClaw::Scraper
- Extended by:
- Callbacks
- Includes:
- Browser
- Defined in:
- lib/eagleclaw.rb
Class Attribute Summary collapse
-
.properties ⇒ Object
Returns the value of attribute properties.
Instance Attribute Summary collapse
-
#data ⇒ Object
A ‘Hash` which holds data collected during a run.
-
#problems ⇒ Object
An ‘Array` which collects.
Class Method Summary collapse
-
.after(context, meth = nil, &block) ⇒ nil
Define a post-processor to run in a certain context.
-
.before(context, meth = nil, &block) ⇒ nil
Define a pre-processor to run in a certain context.
- .prop(prop_name, meth = nil, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Scraper
constructor
Create a new Scraper instance.
-
#reset ⇒ nil
abstract
Reset this scraper instance’s state.
-
#run ⇒ Object
Run the scraper.
Methods included from Callbacks
Methods included from Browser
Constructor Details
#initialize ⇒ Scraper
Create a new EagleClaw::Scraper instance.
By default, just sets @data and @problems to empty ‘Array`s.
94 95 96 97 |
# File 'lib/eagleclaw.rb', line 94 def initialize @data = [] @problems = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class EagleClaw::Browser
Class Attribute Details
.properties ⇒ Object
Returns the value of attribute properties.
13 14 15 |
# File 'lib/eagleclaw.rb', line 13 def properties @properties end |
Instance Attribute Details
#data ⇒ Object
A ‘Hash` which holds data collected during a run.
82 83 84 |
# File 'lib/eagleclaw.rb', line 82 def data @data end |
#problems ⇒ Object
An ‘Array` which collects
86 87 88 |
# File 'lib/eagleclaw.rb', line 86 def problems @problems end |
Class Method Details
.after(: each, : method_name) ⇒ nil .after(: all, : method_name) ⇒ nil .after(: each, &block) ⇒ nil .after(: all, &block) ⇒ nil
Define a post-processor to run in a certain context.
65 66 67 |
# File 'lib/eagleclaw.rb', line 65 def after(context, meth = nil, &block) register([:after, context], meth, &block) end |
.before(: each, : method_name) ⇒ nil .before(: all, : method_name) ⇒ nil .before(: each, &block) ⇒ nil .before(: all, &block) ⇒ nil
Define a pre-processor to run in a certain context.
42 43 44 |
# File 'lib/eagleclaw.rb', line 42 def before(context, meth = nil, &block) register([:before, context], meth, &block) end |
.prop(prop_name, meth = nil, &block) ⇒ Object
69 70 71 72 |
# File 'lib/eagleclaw.rb', line 69 def prop(prop_name, meth = nil, &block) (@properties ||= []) << prop_name.to_sym register([:property, prop_name.to_sym], meth, &block) end |
Instance Method Details
#reset ⇒ nil
108 109 110 111 |
# File 'lib/eagleclaw.rb', line 108 def reset data.clear problems.clear end |
#run ⇒ Object
Run the scraper.
Operating procedure:
-
Run before(:all) blocks.
-
For each property (defined with prop(:prop_name)):
-
Run before(:each) blocks.
-
Run the property itself.
-
Runs after(:each) blocks.
-
-
Runs after(:all) blocks.
-
Return data.
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/eagleclaw.rb', line 128 def run self.class.run_callbacks([:before, :all], self) self.class.properties.each do |property| self.class.run_callbacks([:before, :each], self) self.class.run_callbacks([:property, property], self) self.class.run_callbacks([:after, :each], self) end self.class.run_callbacks([:after, :all], self) data end |