kalculator 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13f752f4822c544a9380ec994d5c5b82590b6978dd7941b71b094bf703966182
4
- data.tar.gz: 34b593efc2ac447d573b42c0a55ae286587745d140890a67fcaba6251828352b
3
+ metadata.gz: 6220f71e922ae69d228c6a9b1e6da291585577338c048587c1b68a9a7a84808c
4
+ data.tar.gz: 8eceb95b3f89519cf58f6ce72d391398a16dfd809015aea5f99c87b74b0a22a2
5
5
  SHA512:
6
- metadata.gz: d422ae52ab12feaefcd11d62890a2237fb019acd8f4ff7f8654273bcaa6c8b78c574e4b8bb1646130e8e1f7bf9a70241a3055297c1d1956e770cfad83147115f
7
- data.tar.gz: 5ababeb0c7d56779087bbb76832c11f9809d4eea954a993449e2e6022626690805aa1e26490092a8814c478aefa196bb8b301676829ef2a4c9bfdf45918c38b5
6
+ metadata.gz: c5affaa47b3d2757ef89b602e38eb246d99aca5378d9f92a4f03d4d904442f170556e2df4327eeabd46bcf542b2ad6209fa11b26da691f79879c1f025e39882a
7
+ data.tar.gz: 738b7ae968c9e4c3374d83d07c10e6142ef9ad5a8c9a965a2997f3c6f6cced157e5239952526f4879b62cdc658375eb5f485b40632a8a082a54c17a948d8dc76
@@ -1,3 +1,5 @@
1
+ require "date"
2
+
1
3
  class Kalculator
2
4
  class Evaluator
3
5
  def initialize(data_source)
@@ -78,6 +80,12 @@ class Kalculator
78
80
  collection.count
79
81
  end
80
82
 
83
+ def date(_, expression)
84
+ value = evaluate(expression)
85
+ raise TypeError, "date only works with Strings, got #{value.inspect}" unless value.is_a?(String)
86
+ Date.parse(value)
87
+ end
88
+
81
89
  def if(_, condition, true_clause, false_clause)
82
90
  if evaluate(condition)
83
91
  evaluate(true_clause)
@@ -24,6 +24,7 @@ class Kalculator
24
24
  rule(/\-?\d+\.\d+/) { |t| [:NUMBER, t.to_f] }
25
25
  rule(/contains/) { |t| :CONTAINS }
26
26
  rule(/count/) { |t| :COUNT }
27
+ rule(/date/) { |t| :DATE }
27
28
  rule(/if/) { |t| :IF }
28
29
  rule(/max/) { |t| :MAX }
29
30
  rule(/min/) { |t| :MIN }
@@ -19,6 +19,9 @@ class Kalculator
19
19
  clause('COUNT LPAREN expression RPAREN') do |_, _, e0, _|
20
20
  [:count, e0]
21
21
  end
22
+ clause('DATE LPAREN expression RPAREN') do |_, _, e0, _|
23
+ [:date, e0]
24
+ end
22
25
  clause('MAX LPAREN expression COMMA expression RPAREN') { |_, _, left, _, right, _| [:max, left, right] }
23
26
  clause('MIN LPAREN expression COMMA expression RPAREN') { |_, _, left, _, right, _| [:min, left, right] }
24
27
  clause('LPAREN expression RPAREN') { |_, expression, _| expression }
@@ -1,3 +1,3 @@
1
1
  class Kalculator
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Ries
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rltk