royw-imdb 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +1 -1
  2. data/lib/imdb/imdb_search.rb +22 -2
  3. metadata +1 -1
data/README CHANGED
@@ -77,6 +77,6 @@ String unescape_html
77
77
  String strip_tags
78
78
  - should strip HTML tags
79
79
 
80
- Finished in 19.495014 seconds
80
+ Finished in 2.751245 seconds
81
81
 
82
82
  56 examples, 0 failures
@@ -5,12 +5,17 @@ class ImdbSearch
5
5
  def initialize(query, search_akas=false)
6
6
  @query = query
7
7
  @search_akas = search_akas
8
+ @cache = {}
8
9
  end
9
10
 
10
11
  def movies
11
12
  @movies ||= parse_movies_from_document
12
13
  end
13
14
 
15
+ def set_cache(cache)
16
+ @cache = cache
17
+ end
18
+
14
19
  # Find the IMDB ID for the current search title
15
20
  # The find can be helped a lot by including a years option that contains
16
21
  # an Array of integers that are the production year (plus/minus a year)
@@ -62,6 +67,21 @@ class ImdbSearch
62
67
  (t1.gsub('more at imdbpro ?', '') == t2)
63
68
  end
64
69
 
70
+ def getMovie(id, title)
71
+ obj = nil
72
+ unless id.blank?
73
+ name = id.to_s
74
+ name += ' ' + title unless title.blank?
75
+ obj = @cache[name]
76
+ if obj.nil?
77
+ obj = ImdbMovie.new(id,title)
78
+ @cache[name] = obj
79
+ end
80
+ end
81
+ obj
82
+ end
83
+
84
+
65
85
  private
66
86
 
67
87
  def document
@@ -76,7 +96,7 @@ class ImdbSearch
76
96
  def parse_exact_match_search_results
77
97
  id = document.at("a[@name='poster']")['href'][/\d+$/]
78
98
  title = document.at("h1").innerHTML.split('<span').first.strip.unescape_html rescue nil
79
- [ImdbMovie.new(id, title)]
99
+ [getMovie(id, title)]
80
100
  end
81
101
 
82
102
  def parse_multi_movie_search_results
@@ -87,7 +107,7 @@ class ImdbSearch
87
107
  end.uniq
88
108
 
89
109
  films = ids_and_titles.map do |id_and_title|
90
- ImdbMovie.new(id_and_title[0], id_and_title[1])
110
+ getMovie(id_and_title[0], id_and_title[1])
91
111
  end.uniq.compact
92
112
 
93
113
  if films.length > 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-imdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Gil