diff options
| author | mo khan <mo@mokhan.ca> | 2013-11-09 09:13:22 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-11-09 09:13:22 -0700 |
| commit | 1e8a16cea7b21a7c48d8727bd4600ac598af2bd0 (patch) | |
| tree | c50a40dd7cb5304cadc3369dc14befa57a008e3f | |
| parent | 4ab92f997537fc16bca4d2433c5947da32dc4425 (diff) | |
split out specification to a separate file.
| -rw-r--r-- | src/movie.coffee | 22 | ||||
| -rw-r--r-- | src/specification.coffee | 20 |
2 files changed, 22 insertions, 20 deletions
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) + |
