porras-imdb 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,6 +5,7 @@ ImdbMovie Indiana Jones and the Last Crusade
5
5
  - should query IMDB url
6
6
  - should get director
7
7
  - should get the poster
8
+ - should get the rating
8
9
  - should get cast members
9
10
  - should get the writers
10
11
  - should get the release date
@@ -64,6 +65,6 @@ String unescape_html
64
65
  String strip_tags
65
66
  - should strip HTML tags
66
67
 
67
- Finished in 2.848225 seconds
68
+ Finished in 3.044303 seconds
68
69
 
69
- 41 examples, 0 failures
70
+ 42 examples, 0 failures
@@ -13,7 +13,11 @@ class ImdbMovie
13
13
  end
14
14
 
15
15
  def poster
16
- document.at("a[@name='poster'] img")['src'] rescue nil
16
+ document.at("a[@name='poster'] img")['src'][/http:.+@@/] + '.jpg' rescue nil
17
+ end
18
+
19
+ def rating
20
+ document.at(".general.rating b").innerHTML.strip.unescape_html.split('/').first.to_f rescue nil
17
21
  end
18
22
 
19
23
  def cast_members
@@ -0,0 +1,186 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe ImdbMovie do
4
+
5
+ describe 'Indiana Jones and the Last Crusade' do
6
+
7
+ before(:each) do
8
+ @imdb_movie = ImdbMovie.new('0097576', 'Indiana Jones and the Last Crusade')
9
+ @imdb_movie.stub!(:open).and_return(open("#{$samples_dir}/sample_movie.html"))
10
+ end
11
+
12
+ it "should query IMDB url" do
13
+ @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0097576/").and_return(open("#{$samples_dir}/sample_movie.html"))
14
+ @imdb_movie.send(:document)
15
+ end
16
+
17
+ it "should get director" do
18
+ @imdb_movie.director.should == 'Steven Spielberg'
19
+ end
20
+
21
+ it "should get the poster" do
22
+ @imdb_movie.poster.should == 'http://ia.media-imdb.com/images/M/MV5BMTkzODA5ODYwOV5BMl5BanBnXkFtZTcwMjAyNDYyMQ@@.jpg'
23
+ end
24
+
25
+ it "should get the rating" do
26
+ @imdb_movie.rating.should == 8.3
27
+ end
28
+
29
+ it "should get cast members" do
30
+ @imdb_movie.cast_members.should include('Harrison Ford')
31
+ @imdb_movie.cast_members.should include('Sean Connery')
32
+ @imdb_movie.cast_members.should include('Denholm Elliott')
33
+ @imdb_movie.cast_members.should include('Alison Doody')
34
+ @imdb_movie.cast_members.should include('John Rhys-Davies')
35
+ @imdb_movie.cast_members.should_not include('more')
36
+ end
37
+
38
+ it "should get the writers" do
39
+ @imdb_movie.writers.should include('George Lucas')
40
+ @imdb_movie.writers.should include('Philip Kaufman')
41
+ @imdb_movie.writers.should_not include('more')
42
+ end
43
+
44
+ it "should get the release date" do
45
+ @imdb_movie.release_date.should be_an_instance_of(Date)
46
+ @imdb_movie.release_date.should == Date.new(1989, 9, 1)
47
+ end
48
+
49
+ it "should get the genres" do
50
+ @imdb_movie.genres.should have(2).strings
51
+ @imdb_movie.genres.should include('Action')
52
+ @imdb_movie.genres.should include('Adventure')
53
+ end
54
+
55
+ it "should get the plot" do
56
+ @imdb_movie.plot.should == "When Dr. Henry Jones Sr. suddenly goes missing while pursuing the Holy Grail, eminent archaeologist Indiana Jones must follow in his father's footsteps and stop the Nazis."
57
+ end
58
+
59
+ it "should get the length" do
60
+ @imdb_movie.length.should == '127 min'
61
+ end
62
+
63
+ it "should get the countries" do
64
+ @imdb_movie.countries.should have(1).string
65
+ @imdb_movie.countries.should include('USA')
66
+ end
67
+
68
+ it "should get the languages" do
69
+ @imdb_movie.languages.should have(3).strings
70
+ @imdb_movie.languages.should include('English')
71
+ @imdb_movie.languages.should include('German')
72
+ @imdb_movie.languages.should include('Greek')
73
+ end
74
+
75
+ it "should get the color" do
76
+ @imdb_movie.color.should == 'Color'
77
+ end
78
+
79
+ it "should get the company" do
80
+ @imdb_movie.company.should == 'Lucasfilm'
81
+ end
82
+
83
+ it "should get some photos" do
84
+ @imdb_movie.photos.should have(10).strings
85
+ @imdb_movie.photos.should include('http://ia.media-imdb.com/images/M/MV5BMTY4MzY3OTY0MF5BMl5BanBnXkFtZTYwODM0OTE3._V1._CR82,0,320,320_SS90_.jpg')
86
+ @imdb_movie.photos.should include('http://ia.media-imdb.com/images/M/MV5BMjAwNTM4ODc3Nl5BMl5BanBnXkFtZTYwNzU0OTE3._V1._CR82,0,320,320_SS90_.jpg')
87
+ end
88
+
89
+ it "should get the tagline" do
90
+ @imdb_movie.tagline.should == "He's back in an all new adventure. Memorial Day 1989."
91
+ end
92
+
93
+ it "should get the aspect ratio" do
94
+ @imdb_movie.aspect_ratio.should == "2.20 : 1"
95
+ end
96
+
97
+ describe "title pre-caching & get_data" do
98
+
99
+ it "should have the original title before querying anything" do
100
+ @imdb_movie.should_not_receive(:open)
101
+ @imdb_movie.title.should == 'Indiana Jones and the Last Crusade'
102
+ end
103
+
104
+ it "should have the updated title after calling get_data" do
105
+ @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0097576/").and_return(open("#{$samples_dir}/sample_movie.html"))
106
+ @imdb_movie.get_data
107
+ @imdb_movie.title.should == 'Indiana Jones and the Last Crusade'
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
114
+
115
+ describe 'Han robado una estrella' do
116
+
117
+ before(:each) do
118
+ @imdb_movie = ImdbMovie.new('0054961', 'Han robado una estrella')
119
+ @imdb_movie.stub!(:open).and_return(open("#{$samples_dir}/sample_incomplete_movie.html"))
120
+ end
121
+
122
+ it "should query IMDB url" do
123
+ @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0054961/").and_return(open("#{$samples_dir}/sample_incomplete_movie.html"))
124
+ @imdb_movie.send(:document)
125
+ end
126
+
127
+ it "should get director" do
128
+ @imdb_movie.director.should == 'Javier Setó'
129
+ end
130
+
131
+ it "should not get the poster" do
132
+ @imdb_movie.poster.should be_nil
133
+ end
134
+
135
+ it "should get cast members" do
136
+ @imdb_movie.cast_members.should include('Rafaela Aparicio')
137
+ @imdb_movie.cast_members.should include('Marujita Díaz')
138
+ @imdb_movie.cast_members.should include('Espartaco Santoni')
139
+ @imdb_movie.cast_members.should_not include('more')
140
+ end
141
+
142
+ it "should get the writers" do
143
+ @imdb_movie.writers.should have(1).string
144
+ @imdb_movie.writers.should include('Paulino Rodrigo')
145
+ end
146
+
147
+ it "should get the release date" do
148
+ @imdb_movie.release_date.should be_an_instance_of(Date)
149
+ @imdb_movie.release_date.should == Date.new(1963, 9, 9)
150
+ end
151
+
152
+ it "should get the genres" do
153
+ @imdb_movie.genres.should == ['Comedy', 'Musical']
154
+ end
155
+
156
+ it "should not get the plot" do
157
+ @imdb_movie.plot.should be_nil
158
+ end
159
+
160
+ it "should get the length" do
161
+ @imdb_movie.length.should == '93 min'
162
+ end
163
+
164
+ it "should get the countries" do
165
+ @imdb_movie.countries.should == ['Spain']
166
+ end
167
+
168
+ it "should get the languages" do
169
+ @imdb_movie.languages.should == ['Spanish']
170
+ end
171
+
172
+ it "should not get the color" do
173
+ @imdb_movie.color.should be_nil
174
+ end
175
+
176
+ it "should get the company" do
177
+ @imdb_movie.company.should == 'Brepi Films'
178
+ end
179
+
180
+ it "should not get any photos" do
181
+ @imdb_movie.photos.should be_empty
182
+ end
183
+
184
+ end
185
+
186
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe ImdbSearch do
4
+
5
+ describe 'Indiana Jones' do
6
+
7
+ before(:each) do
8
+ @imdb_search = ImdbSearch.new('indiana jones')
9
+ @imdb_search.stub!(:open).and_return(open("#{$samples_dir}/sample_search.html"))
10
+ end
11
+
12
+ it "should query IMDB url" do
13
+ @imdb_search.should_receive(:open).with("http://www.imdb.com/find?q=indiana+jones;s=tt").and_return(open("#{$samples_dir}/sample_search.html"))
14
+ @imdb_search.send(:document)
15
+ end
16
+
17
+ describe "movies" do
18
+
19
+ it "should be a collection of ImdbMovie instances" do
20
+ @imdb_search.movies.should be_an_instance_of(Array)
21
+ @imdb_search.movies.should_not be_empty
22
+ @imdb_search.movies.each do |movie|
23
+ movie.should be_an_instance_of(ImdbMovie)
24
+ end
25
+ end
26
+
27
+ it "should include 'Indiana Jones and the Last Crusade'" do
28
+ @imdb_search.movies.map { |m| m.title }.should include('Indiana Jones and the Last Crusade')
29
+ end
30
+
31
+ it "should have titles" do
32
+ @imdb_search.movies.each do |movie|
33
+ movie.title.should_not be_empty
34
+ end
35
+ end
36
+
37
+ it "should not have titles with HTML tags" do
38
+ @imdb_search.movies.each do |movie|
39
+ movie.title.should_not match(/<.+>/)
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ describe 'searches with potential encoding issues' do
48
+
49
+ before(:each) do
50
+ @imdb_search = ImdbSearch.new('torrente')
51
+ @imdb_search.stub!(:open).and_return(open("#{$samples_dir}/sample_spanish_search.html"))
52
+ end
53
+
54
+ describe "movies" do
55
+
56
+ it "should include 'Misión en Marbella'" do
57
+ @imdb_search.movies.map { |m| m.title }.should include('Misión en Marbella')
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + '/../lib/imdb'
2
+
3
+ $samples_dir = File.dirname(__FILE__) + '/samples'
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe String do
4
+
5
+ describe "unescape_html" do
6
+
7
+ it "should convert &amp; to &" do
8
+ "M&amp;M".unescape_html.should == 'M&M'
9
+ end
10
+
11
+ it "should convert &#243; to ó" do
12
+ "&#243;smosis".unescape_html.should == 'ósmosis'
13
+ end
14
+
15
+ end
16
+
17
+ describe "strip_tags" do
18
+
19
+ it "should strip HTML tags" do
20
+ "<em>Hola</em> hola".strip_tags.should == 'Hola hola'
21
+ end
22
+
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porras-imdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Gil
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2009-05-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hpricot
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: chronic
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -36,19 +38,19 @@ executables: []
36
38
 
37
39
  extensions: []
38
40
 
39
- extra_rdoc_files: []
40
-
41
+ extra_rdoc_files:
42
+ - README
41
43
  files:
44
+ - README
45
+ - lib/imdb.rb
42
46
  - lib/imdb/imdb_movie.rb
43
47
  - lib/imdb/imdb_search.rb
44
- - lib/imdb.rb
45
48
  - lib/string_extensions.rb
46
- - README
47
- has_rdoc: false
49
+ has_rdoc: true
48
50
  homepage:
49
51
  post_install_message:
50
- rdoc_options: []
51
-
52
+ rdoc_options:
53
+ - --charset=UTF-8
52
54
  require_paths:
53
55
  - lib
54
56
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -68,7 +70,10 @@ requirements: []
68
70
  rubyforge_project:
69
71
  rubygems_version: 1.2.0
70
72
  signing_key:
71
- specification_version: 2
73
+ specification_version: 3
72
74
  summary: Internet Movie DataBase
73
- test_files: []
74
-
75
+ test_files:
76
+ - spec/imdb_movie_spec.rb
77
+ - spec/imdb_search_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/string_extensions_spec.rb