Class: Scraptacular::Suite
- Inherits:
-
Object
- Object
- Scraptacular::Suite
- Defined in:
- lib/scraptacular/suite.rb
Instance Attribute Summary collapse
-
#default_scraper ⇒ Object
Returns the value of attribute default_scraper.
-
#name ⇒ Object
Returns the value of attribute name.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ Suite
constructor
A new instance of Suite.
- #run(out) ⇒ Object
- #url(url_path, options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Suite
Returns a new instance of Suite.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/scraptacular/suite.rb', line 5 def initialize(name, = {}, &block) @name = name if !.has_key?(:with) raise ArgumentError, "You must supply a default scraper using :with" end @default_scraper = Scraptacular.world.scrapers[[:with]] if @default_scraper.nil? raise ArgumentError, "The supplied scraper :#{options[:with]} does not exist" end @urls = [] instance_eval(&block) end |
Instance Attribute Details
#default_scraper ⇒ Object
Returns the value of attribute default_scraper.
3 4 5 |
# File 'lib/scraptacular/suite.rb', line 3 def default_scraper @default_scraper end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/scraptacular/suite.rb', line 3 def name @name end |
#urls ⇒ Object
Returns the value of attribute urls.
3 4 5 |
# File 'lib/scraptacular/suite.rb', line 3 def urls @urls end |
Instance Method Details
#run(out) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/scraptacular/suite.rb', line 22 def run(out) out.puts " Suite: #{self.name}" results = [] urls.each do |url| out.puts " URL: #{url.path}" scraper = url.scraper scraper ||= default_scraper page = Scraptacular.agent.get(url.path) results += [*scraper.run(page)] end results end |
#url(url_path, options = {}) ⇒ Object
40 41 42 |
# File 'lib/scraptacular/suite.rb', line 40 def url(url_path, = {}) urls << Scraptacular::URL.new(url_path, ) end |