Class: Scrape::DSL
- Inherits:
-
Object
- Object
- Scrape::DSL
- Defined in:
- lib/scrape/dsl.rb
Instance Method Summary collapse
- #enqueue(*urls) ⇒ Object (also: #queue)
-
#initialize(app) ⇒ DSL
constructor
A new instance of DSL.
- #match(matcher, &proc) ⇒ Object
- #site(*urls) ⇒ Object
Constructor Details
#initialize(app) ⇒ DSL
Returns a new instance of DSL.
2 3 4 |
# File 'lib/scrape/dsl.rb', line 2 def initialize app @application = app end |
Instance Method Details
#enqueue(*urls) ⇒ Object Also known as: queue
19 20 21 |
# File 'lib/scrape/dsl.rb', line 19 def enqueue *urls @application.enqueue *urls end |
#match(matcher, &proc) ⇒ Object
13 14 15 16 17 |
# File 'lib/scrape/dsl.rb', line 13 def match matcher, &proc raise ArgumentError, "No sites have been defined" unless defined? @sites matches = @sites.map{|site| site.add_match matcher, &proc } matches.size == 1 ? matches.first : matches end |
#site(*urls) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/scrape/dsl.rb', line 6 def site *urls return @sites if urls.empty? urls = urls.flatten = urls. @sites = urls.map{|url| @application.sites[url] || @application.add_site(url, ) } end |