Class: Scraptacular::World
- Inherits:
-
Object
- Object
- Scraptacular::World
- Defined in:
- lib/scraptacular/world.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#scrapers ⇒ Object
Returns the value of attribute scrapers.
Instance Method Summary collapse
-
#initialize ⇒ World
constructor
A new instance of World.
- #register_group(name, &block) ⇒ Object
- #register_scraper(identifier, &block) ⇒ Object
- #reset ⇒ Object
- #run(options, out = $stdout) ⇒ Object
Constructor Details
#initialize ⇒ World
Returns a new instance of World.
5 6 7 8 |
# File 'lib/scraptacular/world.rb', line 5 def initialize @groups = [] @scrapers = {} end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
3 4 5 |
# File 'lib/scraptacular/world.rb', line 3 def groups @groups end |
#scrapers ⇒ Object
Returns the value of attribute scrapers.
3 4 5 |
# File 'lib/scraptacular/world.rb', line 3 def scrapers @scrapers end |
Instance Method Details
#register_group(name, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/scraptacular/world.rb', line 10 def register_group(name, &block) group = Scraptacular::Group.new(name, &block) @groups << group group end |
#register_scraper(identifier, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/scraptacular/world.rb', line 16 def register_scraper(identifier, &block) scraper = Scraptacular::Scraper.new(identifier, &block) @scrapers[identifier] = scraper scraper end |
#reset ⇒ Object
22 23 24 |
# File 'lib/scraptacular/world.rb', line 22 def reset @results = {} end |
#run(options, out = $stdout) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/scraptacular/world.rb', line 26 def run(, out = $stdout) reset if [:group] groups_to_run = @groups.select { |g| g.name == [:group] } else groups_to_run = @groups end groups_to_run.each do |group| @results[group.name] = group.run(out) end @results end |