From 1e8a16cea7b21a7c48d8727bd4600ac598af2bd0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 9 Nov 2013 09:13:22 -0700 Subject: split out specification to a separate file. --- src/movie.coffee | 22 ++-------------------- src/specification.coffee | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 src/specification.coffee diff --git a/src/movie.coffee b/src/movie.coffee index e00a4f9..b227dda 100644 --- a/src/movie.coffee +++ b/src/movie.coffee @@ -1,3 +1,5 @@ +WhereSpecification = require('./specification') + module.exports = class Movie constructor: (attributes) -> @title = attributes['title'] @@ -10,23 +12,3 @@ 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) - return false if item[key] != @condition[key] - return true - - or: (other_specification) -> - new OrSpecification(this, other_specification) - diff --git a/src/specification.coffee b/src/specification.coffee new file mode 100644 index 0000000..3cdd1dc --- /dev/null +++ b/src/specification.coffee @@ -0,0 +1,20 @@ +module.exports = class OrSpecification + constructor: (left, right) -> + @left = left + @right = right + + matches: (item) -> + @left.matches(item) || @right.matches(item) + +module.exports = class WhereSpecification + constructor: (condition) -> + @condition = condition + + matches: (item) -> + for key in Object.keys(@condition) + return false if item[key] != @condition[key] + return true + + or: (other_specification) -> + new OrSpecification(this, other_specification) + -- cgit v1.2.3