Class: ImdbSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/imdb/imdb_search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, search_akas = false) ⇒ ImdbSearch

Returns a new instance of ImdbSearch.



5
6
7
8
9
# File 'lib/imdb/imdb_search.rb', line 5

def initialize(query, search_akas=false)
  @query = query
  @search_akas = search_akas
  @cache = {}
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'lib/imdb/imdb_search.rb', line 3

def query
  @query
end

Instance Method Details

#find_id(options = {}) ⇒ Object

Find the IMDB ID for the current search title The find can be helped a lot by including a years option that contains an Array of integers that are the production year (plus/minus a year) and the release year.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/imdb/imdb_search.rb', line 23

def find_id(options={})
  id = nil
  found_movies = self.movies.select do |m|
    result = true
    unless options[:years].nil?
      result = options[:years].include?(m.release_year.to_i)
    end
    result
  end
#     p found_movies.collect{|m| [m.id, m.title, m.year]}
  ids = found_movies.collect{|m| m.id}.uniq.compact
  if ids.length == 1
    id = "tt#{ids[0]}"
  end
  id
end

#moviesObject



11
12
13
# File 'lib/imdb/imdb_search.rb', line 11

def movies
  @movies ||= parse_movies_from_document
end

#set_cache(cache) ⇒ Object



15
16
17
# File 'lib/imdb/imdb_search.rb', line 15

def set_cache(cache)
  @cache = cache
end