Class: ImdbSearch
- Inherits:
-
Object
- Object
- ImdbSearch
- Defined in:
- lib/imdb/imdb_search.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#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.
-
#initialize(query, search_akas = false) ⇒ ImdbSearch
constructor
A new instance of ImdbSearch.
- #movies ⇒ Object
- #set_cache(cache) ⇒ Object
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
#query ⇒ Object (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(={}) id = nil found_movies = self.movies.select do |m| result = true unless [:years].nil? result = [: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 |
#movies ⇒ Object
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 |