summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-11-09 09:55:37 -0700
committermo khan <mo@mokhan.ca>2013-11-09 09:55:37 -0700
commitbfcf4b39393fb8762b45657c0c16af0d4bf2d412 (patch)
tree40f6e44bb6ab70a7f5ba563f67c67b7a45e3012a
parentdcdb607727da93c066e81894844144ae3f46c12d (diff)
create not specification.
-rw-r--r--src/movie_library.coffee4
-rw-r--r--src/not_specification.coffee12
-rw-r--r--src/specification.coffee3
-rw-r--r--test/movie_library_spec.coffee2
4 files changed, 16 insertions, 5 deletions
diff --git a/src/movie_library.coffee b/src/movie_library.coffee
index 26b5095..7934d81 100644
--- a/src/movie_library.coffee
+++ b/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
diff --git a/src/not_specification.coffee b/src/not_specification.coffee
new file mode 100644
index 0000000..3643310
--- /dev/null
+++ b/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)
+
diff --git a/src/specification.coffee b/src/specification.coffee
index 6a98feb..5c1767d 100644
--- a/src/specification.coffee
+++ b/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)
diff --git a/test/movie_library_spec.coffee b/test/movie_library_spec.coffee
index 0f97edf..ac9d128 100644
--- a/test/movie_library_spec.coffee
+++ b/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)