Class: Scrape::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/scrape/dsl.rb

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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
  options = urls.extract_options!
  @sites = urls.map{|url| @application.sites[url] || @application.add_site(url, options) }
end