royw-imdb 0.0.13 → 0.0.14

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 +3 -2
  2. data/lib/imdb/imdb_movie.rb +22 -13
  3. metadata +2 -2
data/README CHANGED
@@ -27,6 +27,7 @@ ImdbMovie Indiana Jones and the Last Crusade
27
27
  - should get the aspect ratio
28
28
  - should convert to xml
29
29
  - should convert to yaml
30
+ - should be able to convert to and then from xml
30
31
 
31
32
  ImdbMovie Han robado una estrella
32
33
  - should query IMDB url
@@ -89,6 +90,6 @@ String unescape_html
89
90
  String strip_tags
90
91
  - should strip HTML tags
91
92
 
92
- Finished in 3.710128 seconds
93
+ Finished in 4.131553 seconds
93
94
 
94
- 64 examples, 0 failures
95
+ 65 examples, 0 failures
@@ -165,10 +165,17 @@ class ImdbMovie
165
165
  # return a hash with country abbreviations for keys and the certification string for the value
166
166
  # example: {'USA' => 'Approved'}
167
167
  def certifications
168
- cert_hash = {}
169
- certs = document.search("h5[text()='Certification:'] ~ a[@href*=/List?certificates']").map { |link| link.innerHTML.strip } rescue []
170
- certs.each { |line| cert_hash[$1] = $2 if line =~ /(.*):(.*)/ }
171
- cert_hash
168
+ certs = []
169
+ cert_set = document.search("h5[text()='Certification:'] ~ a[@href*=/List?certificates']").map { |link| link.innerHTML.strip } rescue []
170
+ cert_set.each do |line|
171
+ if line =~ /(.*):(.*)/
172
+ cert_hash = {}
173
+ cert_hash['country'] = $1
174
+ cert_hash['rating'] = $2
175
+ certs << cert_hash
176
+ end
177
+ end
178
+ certs
172
179
  end
173
180
 
174
181
  def to_hash
@@ -210,18 +217,20 @@ class ImdbMovie
210
217
  def document
211
218
  attempts = 0
212
219
  begin
213
- if ImdbMovie::use_html_cache
214
- begin
215
- filespec = self.url.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
216
- html = open(filespec).read
217
- rescue Exception
220
+ if @document.nil?
221
+ if ImdbMovie::use_html_cache
222
+ begin
223
+ filespec = self.url.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
224
+ html = open(filespec).read
225
+ rescue Exception
226
+ html = open(self.url).read
227
+ cache_html_files(html)
228
+ end
229
+ else
218
230
  html = open(self.url).read
219
- cache_html_files(html)
220
231
  end
221
- else
222
- html = open(self.url).read
232
+ @document = Hpricot(html)
223
233
  end
224
- @document ||= Hpricot(html)
225
234
  rescue Exception => e
226
235
  attempts += 1
227
236
  if attempts > MAX_ATTEMPTS
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.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Gil
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-29 00:00:00 -07:00
12
+ date: 2009-04-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency