summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-11-09 08:28:02 -0700
committermo khan <mo@mokhan.ca>2013-11-09 08:28:02 -0700
commiteac28ff73ae2ef2738a058d60a2e4d35a610db60 (patch)
treee161df9c514b626e527c1f78574ece35819ccc4e
parentabd49e37bdb821c8639da208e725135e5df3f4ff (diff)
extract method to search using specification.
-rw-r--r--src/movie.coffee11
-rw-r--r--src/movie_library.coffee8
-rw-r--r--test/movie_library_spec.coffee2
3 files changed, 16 insertions, 5 deletions
diff --git a/src/movie.coffee b/src/movie.coffee
index bf2e77d..9d22e85 100644
--- a/src/movie.coffee
+++ b/src/movie.coffee
@@ -6,3 +6,14 @@ module.exports = class Movie
equals: (other) ->
@title == other["title"]
+
+ @by: (studio) ->
+ console.log(studio)
+ new StudioSpecification(studio)
+
+class StudioSpecification
+ constructor: (studio) ->
+ @studio = studio
+
+ matches: (movie) ->
+ @studio == movie.studio
diff --git a/src/movie_library.coffee b/src/movie_library.coffee
index 69af878..5b77972 100644
--- a/src/movie_library.coffee
+++ b/src/movie_library.coffee
@@ -20,6 +20,10 @@ Enumerable =
results.push(item) if predicate(item)
results
+ all: (specification) ->
+ @find_all (movie) ->
+ specification.matches(movie)
+
moduleKeywords = ['extended', 'included']
class Module
@@ -46,10 +50,6 @@ module.exports = class MovieLibrary extends Module
for movie in @movies
visitor(movie)
- find_all_movies_by_pixar: ->
- @find_all (movie) =>
- movie.studio == Studio.Pixar
-
find_movies_by_pixar_or_disney: ->
@find_all (movie) =>
movie.studio == Studio.Pixar || movie.studio == Studio.Disney
diff --git a/test/movie_library_spec.coffee b/test/movie_library_spec.coffee
index 9f6ddcc..8e9b0f6 100644
--- a/test/movie_library_spec.coffee
+++ b/test/movie_library_spec.coffee
@@ -49,7 +49,7 @@ describe "MovieLibrary", ->
@sut.add(movie)
it "can find all pixar movies", ->
- results = @sut.find_all_movies_by_pixar()
+ results = @sut.all(Movie.by(Studio.Pixar))
results.should.include(@toy_story)
results.should.include(@up)
results.should.include(@cars)