mongo_inspired_compare 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mongo_inspired_compare.rb +46 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59bdc9bce2a74975ebba9c8d23d8e430e5d24cf7
4
- data.tar.gz: a1d1f4d4914016fdbaca22d9f49f821864719355
3
+ metadata.gz: 54d2f148fd4c0538810677f73edfab5ccd1bc6f3
4
+ data.tar.gz: cd769dfdcdf43dbccfe807458b225d55ea597094
5
5
  SHA512:
6
- metadata.gz: 20cb87fa8e2787634f189bbcb88eb217c248311e881fe4296a6137512be14afb910e144ca0d73a22346efac59058c69dc62fcaf35807d1f53830a74a7fb2c9cb
7
- data.tar.gz: 555dadd69e083dbf6bbc49e140800d4a4fb1b5c2d6cced50377c535df5f1cdbf10e4e5e5dc09046e243772445c0a3a31c55eab476e1ec36d7f9eb9dd0682aad7
6
+ metadata.gz: 79af9b7ef0fe5a31147605b166bfdc595a55b1ce95ac4c41dde1dd87ab1a198e6882f341eb1fdaa3bf8a1226b4e28f91232fb5d7bc1dcddb3435b227a69bf93f
7
+ data.tar.gz: 296efcf3ffd4f2c85adea51beb6dd3f3bc9f843775c5bb1e0130509d20bda8c553aa3295628d02296738ca2ee7552ed0cfaae62f4f2affef9021b07ce31bc1f1
@@ -1,8 +1,50 @@
1
1
  class MongoInspiredCompare
2
- # mongo-inspired syntax for criteria
3
- # if criterion is not hashes then simply tests for equality
4
- # if criteron is a hash, then it considers it to be {operator: comparitor}
5
- # it handles some smart conversion of "1.2" to 1.2 if the comparitor is a number
2
+
3
+ ##
4
+ # Takes a value and a comparitor and returns true or false
5
+ #
6
+ # === Basic Comparisons
7
+ # > MongoInspiredCompare.compare( 5, 5 )
8
+ # => true
9
+ #
10
+ # > MongoInspiredCompare.compare( 5, 6 )
11
+ # => false
12
+ #
13
+ #
14
+ # === Basic Operators
15
+ # > MongoInspiredCompare.compare( 5, {"$gte"=>5} )
16
+ # => true
17
+ #
18
+ # > MongoInspiredCompare.compare( 5, {"$lt"=>5} )
19
+ # => false
20
+ #
21
+ # > MongoInspiredCompare.compare( 5, {"$in"=>[1, 2, 3, 4, 5]} )
22
+ # /Users/daviddo/Documents/mongo_inspired_compare/lib/mongo_inspired_compare.rb:13: warning: constant ::Fixnum is deprecated
23
+ # => true
24
+ #
25
+ # > MongoInspiredCompare.compare( 5, {"$nin"=>[1, 2, 3, 4, 5]} )
26
+ # => false
27
+ #
28
+ #
29
+ # === Nesting
30
+ # > MongoInspiredCompare.compare( 5, {"$in"=>[{"$lt"=>5}, {"$gte"=>5}]} )
31
+ # => true
32
+ #
33
+ #
34
+ # === And/or Operators
35
+ # > MongoInspiredCompare.compare( 5, {"$or"=>[{"$lt"=>5}, {"$gte"=>5}]} )
36
+ # => true
37
+ #
38
+ # > MongoInspiredCompare.compare( 5, {"$and"=>[{"$lt"=>5}, {"$gte"=>5}]} )
39
+ # => false
40
+ #
41
+ #
42
+ # === Invariance
43
+ # > MongoInspiredCompare.compare( "5", {"$gte"=>5} )
44
+ # => true
45
+ #
46
+ # > MongoInspiredCompare.compare( "5x", {"$gte"=>5} )
47
+ # => false
6
48
 
7
49
  def self.compare( val, criterion )
8
50
  if criterion.class != Hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_inspired_compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Do