From bfcf4b39393fb8762b45657c0c16af0d4bf2d412 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 9 Nov 2013 09:55:37 -0700 Subject: create not specification. --- src/movie_library.coffee | 4 ---- src/not_specification.coffee | 12 ++++++++++++ src/specification.coffee | 3 +++ test/movie_library_spec.coffee | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/not_specification.coffee 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) -- cgit v1.2.3