kalculator 0.5.1 → 0.5.2
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 +6 -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: 4fd2684ec05188a764da05fae5593566ab7122191864da22ae2296b89d8e1185
|
4
|
+
data.tar.gz: d4f25af127744abcfe43f13281169374cd678ec9964c96b0f365bbf8de69762c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b361d425d87505bab75a23f84a9e8073b90a551d3aeffe33b39cae270dbb49a7925ea9bc90c66e553bc9c2bf6acc092732bc93998e7c1228f7b2c47a873308e8
|
7
|
+
data.tar.gz: d2bf943a2fa7e5a9693cb52bbb4ccce40f267b3b90c97fdc99050c890eb03e93395269f04f9ab752560e43667cc362c1c02abb677eb8bc4bd7c11241d231a756
|
data/lib/kalculator/evaluator.rb
CHANGED
@@ -72,6 +72,12 @@ class Kalculator
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def count(_, collection)
|
76
|
+
collection = evaluate(collection)
|
77
|
+
raise TypeError, "count only works with Enumerable types, got #{collection.inspect}" unless collection.is_a?(Enumerable)
|
78
|
+
collection.count
|
79
|
+
end
|
80
|
+
|
75
81
|
def if(_, condition, true_clause, false_clause)
|
76
82
|
if evaluate(condition)
|
77
83
|
evaluate(true_clause)
|
data/lib/kalculator/lexer.rb
CHANGED
@@ -23,6 +23,7 @@ class Kalculator
|
|
23
23
|
rule(/\-?\.\d+/) { |t| [:NUMBER, t.to_f] }
|
24
24
|
rule(/\-?\d+\.\d+/) { |t| [:NUMBER, t.to_f] }
|
25
25
|
rule(/contains/) { |t| :CONTAINS }
|
26
|
+
rule(/count/) { |t| :COUNT }
|
26
27
|
rule(/if/) { |t| :IF }
|
27
28
|
rule(/sum/) { |t| :SUM }
|
28
29
|
rule(/true/) { |t| :TRUE }
|
data/lib/kalculator/parser.rb
CHANGED
@@ -16,6 +16,9 @@ class Kalculator
|
|
16
16
|
clause('SUM LPAREN expression RPAREN') do |_, _, e0, _|
|
17
17
|
[:sum, e0]
|
18
18
|
end
|
19
|
+
clause('COUNT LPAREN expression RPAREN') do |_, _, e0, _|
|
20
|
+
[:count, e0]
|
21
|
+
end
|
19
22
|
clause('LPAREN expression RPAREN') { |_, expression, _| expression }
|
20
23
|
clause('LBRACKET expressions RBRACKET') { |_, expressions, _| [:list, expressions] }
|
21
24
|
|
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.5.
|
4
|
+
version: 0.5.2
|
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-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rltk
|