Commit f0a21e1
Changed files (3)
src/movie.coffee
@@ -10,12 +10,23 @@ module.exports = class Movie
@where: (condition) ->
new WhereSpecification(condition)
+class OrSpecification
+ constructor: (left, right) ->
+ @left = left
+ @right = right
+
+ matches: (item) ->
+ @left.matches(item) || @right.matches(item)
+
class WhereSpecification
constructor: (condition) ->
@condition = condition
matches: (item) ->
for key in Object.keys(@condition)
- item[key] == @condition[key]
+ return false if item[key] != @condition[key]
+ return true
+ or: (other_specification) ->
+ new OrSpecification(this, other_specification)
src/movie_library.coffee
@@ -50,10 +50,6 @@ module.exports = class MovieLibrary extends Module
for movie in @movies
visitor(movie)
- find_movies_by_pixar_or_disney: ->
- @find_all (movie) =>
- movie.studio == Studio.Pixar || movie.studio == Studio.Disney
-
find_movies_not_published_by_pixar: ->
@find_all (movie) =>
movie.studio != Studio.Pixar
test/movie_library_spec.coffee
@@ -57,7 +57,7 @@ describe "MovieLibrary", ->
it 'finds all movies published by pixar or disney', ->
- results = @sut.find_movies_by_pixar_or_disney()
+ results = @sut.all(Movie.where(studio: Studio.Pixar).or(Movie.where(studio: Studio.Disney)))
results.length.should.equal(7)
results.should.include(@toy_story)
results.should.include(@up)