Commit bfcf4b3

mo khan <mo@mokhan.ca>
2013-11-09 16:55:37
create not specification.
1 parent dcdb607
src/movie_library.coffee
@@ -18,10 +18,6 @@ module.exports = class MovieLibrary extends Module
     for movie in @movies
       visitor(movie)
 
-  find_movies_not_published_by_pixar: ->
-    @find_all (movie) =>
-      movie.studio != Studio.Pixar
-
   find_movies_released_after_2004: ->
     @find_all (movie) =>
       movie.year_published > 2004
src/not_specification.coffee
@@ -0,0 +1,12 @@
+Module = require('./module')
+Specification = require('./specification')
+
+module.exports = class NotSpecification extends Module
+  @include Specification
+
+  constructor: (other) ->
+    @other = other
+
+  matches: (item) ->
+    !@other.matches(item)
+
src/specification.coffee
@@ -1,6 +1,9 @@
 Module = require('./module')
 OrSpecification = require('./or_specification')
+NotSpecification = require('./not_specification')
 
 module.exports = Specification =
   or: (other_specification) ->
     new OrSpecification(this, other_specification)
+  not: ->
+    new NotSpecification(this)
test/movie_library_spec.coffee
@@ -68,7 +68,7 @@ describe "MovieLibrary", ->
        results.should.include(@pinocchio)
 
      it "finds all movies not published by pixar", ->
-       results = @sut.find_movies_not_published_by_pixar()
+       results = @sut.all(Movie.where(studio: Studio.Pixar).not())
        results.length.should.equal(6)
        results.should.include(@fantasia)
        results.should.include(@dumbo)