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 +4 -4
- data/lib/kalculator/evaluator.rb +8 -0
- data/lib/kalculator/lexer.rb +1 -0
- data/lib/kalculator/parser.rb +3 -0
- data/lib/kalculator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6220f71e922ae69d228c6a9b1e6da291585577338c048587c1b68a9a7a84808c
|
4
|
+
data.tar.gz: 8eceb95b3f89519cf58f6ce72d391398a16dfd809015aea5f99c87b74b0a22a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5affaa47b3d2757ef89b602e38eb246d99aca5378d9f92a4f03d4d904442f170556e2df4327eeabd46bcf542b2ad6209fa11b26da691f79879c1f025e39882a
|
7
|
+
data.tar.gz: 738b7ae968c9e4c3374d83d07c10e6142ef9ad5a8c9a965a2997f3c6f6cced157e5239952526f4879b62cdc658375eb5f485b40632a8a082a54c17a948d8dc76
|
data/lib/kalculator/evaluator.rb
CHANGED
@@ -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)
|
data/lib/kalculator/lexer.rb
CHANGED
data/lib/kalculator/parser.rb
CHANGED
@@ -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 }
|
data/lib/kalculator/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rltk
|