Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merged kalos' cast_members. Closes #23

  • Loading branch information...
commit 8fab9fcd6cf3434039119c86220088ad1fd45b26 2 parents 1a1df03 + 2231ee4
@ariejan authored
Showing with 42 additions and 0 deletions.
  1. +16 −0 lib/imdb/movie.rb
  2. +26 −0 spec/imdb/movie_spec.rb
View
16 lib/imdb/movie.rb
@@ -28,6 +28,22 @@ def cast_member_ids
document.search("table.cast td.nm a").map {|l| l['href'].sub(%r{^/name/(.*)/}, '\1') }
end
+ # Returns an array with cast characters
+ def cast_characters
+ document.search("table.cast td.char").map { |link| link.innerText } rescue []
+ end
+
+ # Returns an array with cast members and characters
+ def cast_members_characters(sep = '=>')
+ memb_char = Array.new
+ i = 0
+ self.cast_members.each{|m|
+ memb_char[i] = "#{self.cast_members[i]} #{sep} #{self.cast_characters[i]}"
+ i=i+1
+ }
+ return memb_char
+ end
+
# Returns the name of the director
def director
document.search("h5[text()^='Director'] ~ a").map { |link| link.innerHTML.strip.imdb_unescape_html } rescue []
View
26 spec/imdb/movie_spec.rb
@@ -22,6 +22,32 @@
cast.should include("Bonnie Bedelia")
cast.should include("Alan Rickman")
end
+
+ it "should find the cast characters" do
+ char = @movie.cast_characters
+
+ char.should be_an(Array)
+ char.should include("Karl")
+ char.should include("Officer John McClane")
+ char.should include("Police Detective (uncredited)")
+ char.should include("Hostage")
+ end
+
+ it "should associates the cast members to the charachters" do
+ cast = @movie.cast_members
+ char = @movie.cast_characters
+ cast_char = @movie.cast_members_characters
+
+ cast_char[0].should eql("#{cast[0]} => #{char[0]}")
+ cast_char[10].should eql("#{cast[10]} => #{char[10]}")
+ cast_char[-1].should eql("#{cast[-1]} => #{char[-1]}")
+
+ cast_char = @movie.cast_members_characters('as')
+
+ cast_char[1].should eql("#{cast[1]} as #{char[1]}")
+ cast_char[11].should eql("#{cast[11]} as #{char[11]}")
+ cast_char[-2].should eql("#{cast[-2]} as #{char[-2]}")
+ end
describe 'fetching a list of imdb actor ids for the cast members' do
it 'should not require arguments' do
Please sign in to comment.
Something went wrong with that request. Please try again.