Class: GoogleMovies47::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/google_movies47/crawler.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Crawler

Returns a new instance of Crawler.

Raises:

  • (MissingLocationArgument)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/google_movies47/crawler.rb', line 11

def initialize(options = {})
  
  raise MissingLocationArgument unless options[:city] and options[:state]
  
  language = options[:language] || 'en'
  
  days_ahead = options[:days_ahead] || 0
  raise WrongDaysAheadArgument unless days_ahead.kind_of? Integer and 0 >= days_ahead
  
  @parser = GoogleMovies47::Parser.new(language)
  
  search_url = "http://www.google.com/movies?hl=#{language}" \
                "&near=#{options[:city]}%2C+#{options[:state]}&date=#{days_ahead}"
  
  @agent = Mechanize.new
  page = @agent.get(search_url)
  
  crawl_result_pages(page)
  
end

Instance Method Details

#moviesObject



32
33
34
# File 'lib/google_movies47/crawler.rb', line 32

def movies
  @parser.movies
end

#theatersObject



36
37
38
# File 'lib/google_movies47/crawler.rb', line 36

def theaters
  @parser.theaters
end