movie_searcher 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,18 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- movie_searcher (0.0.2)
4
+ movie_searcher (0.0.6)
5
+ hintable_levenshtein
5
6
  httparty
6
- levenshtein
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
+ ZenTest (4.4.2)
12
+ autotest (4.4.6)
13
+ ZenTest (>= 4.4.1)
14
+ autotest-fsevent (0.2.4)
15
+ sys-uname
16
+ autotest-growl (0.2.9)
17
+ autotest-standalone (4.5.4)
11
18
  crack (0.1.8)
12
19
  diff-lcs (1.1.2)
20
+ hintable_levenshtein (0.0.3)
13
21
  httparty (0.7.3)
14
22
  crack (= 0.1.8)
15
- levenshtein (0.2.0)
16
23
  rspec (2.4.0)
17
24
  rspec-core (~> 2.4.0)
18
25
  rspec-expectations (~> 2.4.0)
@@ -21,10 +28,15 @@ GEM
21
28
  rspec-expectations (2.4.0)
22
29
  diff-lcs (~> 1.1.2)
23
30
  rspec-mocks (2.4.0)
31
+ sys-uname (0.8.5)
24
32
 
25
33
  PLATFORMS
26
34
  ruby
27
35
 
28
36
  DEPENDENCIES
37
+ autotest
38
+ autotest-fsevent
39
+ autotest-growl
40
+ autotest-standalone
29
41
  movie_searcher!
30
42
  rspec
data/README.md CHANGED
@@ -98,4 +98,4 @@ The `actors`, `writers` and `directors` accessors returns an `ImdbParty::Person`
98
98
 
99
99
  ## Requirements
100
100
 
101
- The gem is tested in OS X 10.6.6 using Ruby 1.8.7.
101
+ The gem is tested in OS X 10.6.6 using Ruby 1.8.7 and 1.9.2
@@ -0,0 +1,27 @@
1
+ # Some code borrowed from http://www.erikveen.dds.nl/levenshtein/doc/index.html
2
+ require 'hintable_levenshtein'
3
+
4
+ class Levenshtein
5
+ def self.distance(s1, s2, threshold = nil)
6
+
7
+ # If the arguments is nil
8
+ s1 = s1.to_s unless s1
9
+ s2 = s2.to_s unless s2
10
+
11
+ s1, s2 = s2, s1 if s1.length > s2.length # s1 is the short one; s2 is the long one.
12
+
13
+ if s2.length == 0
14
+ 0.0 # Since s1.length < s2.length, s1 must be empty as well.
15
+ else
16
+ if threshold
17
+ if (d = HintableLevenshtein.new.distance(s1, s2).to_f/s2.length) <= threshold
18
+ d
19
+ else
20
+ nil
21
+ end
22
+ else
23
+ HintableLevenshtein.new.distance(s1, s2).to_f/s2.length
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  require "imdb_party"
2
- require 'levenshtein'
2
+ require 'imdb_party/levenshtein'
3
3
 
4
4
  class MovieSearcher
5
5
  attr_accessor :options
@@ -49,7 +49,7 @@ class MovieSearcher
49
49
  title = title.gsub(/[^a-z0-9]/i, '').gsub(/(19|20)\d{2}/, '')
50
50
 
51
51
  movie = movies.map do |movie|
52
- [movie, Levenshtein.normalized_distance(movie[:title].gsub(/[^a-z0-9]/i, ''), title, @options[:limit])]
52
+ [movie, Levenshtein.distance(movie[:title].gsub(/[^a-z0-9]/i, ''), title, @options[:limit])]
53
53
  end.reject do |value|
54
54
  value.last.nil?
55
55
  end.sort_by do |_,value|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "movie_searcher"
6
- s.version = "0.0.4"
6
+ s.version = "0.0.6"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Linus Oleander", "Jon Maddox"]
9
9
  s.email = ["linus@oleander.nu", "jon@mustacheinc.com"]
@@ -17,6 +17,10 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency('httparty')
20
- s.add_dependency('levenshtein')
20
+ s.add_dependency('hintable_levenshtein')
21
21
  s.add_development_dependency('rspec')
22
+ s.add_development_dependency('autotest-standalone')
23
+ s.add_development_dependency('autotest')
24
+ s.add_development_dependency('autotest-growl')
25
+ s.add_development_dependency('autotest-fsevent')
22
26
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Levenshtein do
4
+ it "should return the right value when no threshold is being defined" do
5
+ Levenshtein.distance("first", "last").should eq(0.6)
6
+ end
7
+
8
+ it "should return nil value when a threshold is being passed" do
9
+ Levenshtein.distance("first", "last", 0.1).should be_nil
10
+ end
11
+
12
+ it "should not return nil value when a threshold is being passed" do
13
+ Levenshtein.distance("first", "last", 0.8).should_not be_nil
14
+ end
15
+
16
+ it "should not change when a threshold is being passed" do
17
+ Levenshtein.distance("first", "last", 0.8).should eq(0.6)
18
+ end
19
+
20
+ it "should be tested?" do
21
+ Levenshtein.distance("first", "").should eq(1)
22
+ end
23
+
24
+ it "should return zero when to strings are equal" do
25
+ Levenshtein.distance("abc123", "abc123").should eq(0)
26
+ end
27
+
28
+ it "should never return a value larger then 1" do
29
+ Levenshtein.distance("asdasdasdasdasdasdasdasdasdasdasdasd", "a").should <= 1
30
+ end
31
+
32
+ it "should not crash if one if the arguments is nil" do
33
+ lambda do
34
+ Levenshtein.distance(nil, "")
35
+ Levenshtein.distance(nil, nil)
36
+ Levenshtein.distance("", nil)
37
+ end.should_not raise_error
38
+ end
39
+
40
+ it "should return the same value using nil as an empty string" do
41
+ Levenshtein.distance(nil, nil).should eq(Levenshtein.distance("", ""))
42
+ Levenshtein.distance(nil, "Hello").should eq(Levenshtein.distance("", "Hell0"))
43
+ end
44
+ end
@@ -101,21 +101,25 @@ describe MovieSearcher, "should work as before" do
101
101
 
102
102
  it "have genres" do
103
103
  @movie.genres.should be_instance_of(Array)
104
+ @movie.genres.each{|genre| genre.should be_instance_of(String)}
104
105
  @movie.should have(4).genres
105
106
  end
106
107
 
107
108
  it "have actors" do
108
109
  @movie.actors.should be_instance_of(Array)
110
+ @movie.actors.each{|actor| actor.should be_instance_of(ImdbParty::Person)}
109
111
  @movie.should have(4).actors
110
112
  end
111
113
 
112
114
  it "have directors" do
113
115
  @movie.directors.should be_instance_of(Array)
116
+ @movie.directors.each{|director| director.should be_instance_of(ImdbParty::Person)}
114
117
  @movie.should have(2).directors
115
118
  end
116
119
 
117
120
  it "have writers" do
118
121
  @movie.writers.should be_instance_of(Array)
122
+ @movie.writers.each{|writer| writer.should be_instance_of(ImdbParty::Person)}
119
123
  @movie.should have(2).writers
120
124
  end
121
125
 
@@ -161,27 +165,27 @@ describe MovieSearcher, "should still have the same people" do
161
165
  @movie = MovieSearcher.find_movie_by_id("tt0382932")
162
166
  end
163
167
 
164
- it "have a name" do
168
+ it "should have a name" do
165
169
  @movie.actors.map(&:name).should include('Patton Oswalt')
166
170
  end
167
171
 
168
- it "have a role" do
172
+ it "should have a role" do
169
173
  @movie.actors.map(&:role).should include('Remy')
170
174
  end
171
175
 
172
- it "have a name" do
176
+ it "should have a name" do
173
177
  @movie.directors.map(&:name).should include('Brad Bird')
174
178
  end
175
179
 
176
- it "not have a role" do
180
+ it "should not have a role" do
177
181
  @movie.directors.first.role.should be_nil
178
182
  end
179
183
 
180
- it "have a name" do
184
+ it "should have a name" do
181
185
  @movie.writers.map(&:name).should include('Brad Bird')
182
186
  end
183
187
 
184
- it "not have a role" do
188
+ it "should not have a role" do
185
189
  @movie.writers.first.role.should be_nil
186
190
  end
187
191
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rspec'
2
2
  require "#{File.dirname(__FILE__)}/../lib/movie_searcher.rb"
3
+ require "#{File.dirname(__FILE__)}/../lib/imdb_party/levenshtein.rb"
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.mock_with :rspec
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: movie_searcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Linus Oleander
@@ -34,7 +34,7 @@ dependencies:
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: levenshtein
37
+ name: hintable_levenshtein
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
@@ -61,6 +61,62 @@ dependencies:
61
61
  version: "0"
62
62
  type: :development
63
63
  version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: autotest-standalone
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: autotest
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: autotest-growl
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ name: autotest-fsevent
108
+ prerelease: false
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ type: :development
119
+ version_requirements: *id007
64
120
  description: IMDB client using the IMDB API that their iPhone app uses. It can also figure out what movie you are looking for just by looking at the release name of the movie
65
121
  email:
66
122
  - linus@oleander.nu
@@ -84,10 +140,12 @@ files:
84
140
  - lib/imdb_party.rb
85
141
  - lib/imdb_party/httparty_icebox.rb
86
142
  - lib/imdb_party/imdb.rb
143
+ - lib/imdb_party/levenshtein.rb
87
144
  - lib/imdb_party/movie.rb
88
145
  - lib/imdb_party/person.rb
89
146
  - lib/movie_searcher.rb
90
147
  - movie_searcher.gemspec
148
+ - spec/levenshtein_spec.rb
91
149
  - spec/movie_searcher_spec.rb
92
150
  - spec/spec_helper.rb
93
151
  has_rdoc: true
@@ -125,5 +183,6 @@ signing_key:
125
183
  specification_version: 3
126
184
  summary: IMDB client using the IMDB API that their iPhone app uses
127
185
  test_files:
186
+ - spec/levenshtein_spec.rb
128
187
  - spec/movie_searcher_spec.rb
129
188
  - spec/spec_helper.rb