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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5026dd4c73a2ebf6f64a18d11d6ef1c8838f902a4fb9fdee31bba43c0819d998
4
- data.tar.gz: dacfcdd98e1bc4c08048052b1f4ce4fa94449ac05d7217842c9fbfbce8c0efc6
3
+ metadata.gz: 4fd2684ec05188a764da05fae5593566ab7122191864da22ae2296b89d8e1185
4
+ data.tar.gz: d4f25af127744abcfe43f13281169374cd678ec9964c96b0f365bbf8de69762c
5
5
  SHA512:
6
- metadata.gz: 35c4bab92d9ed7b895f7f60231a8cfbd01a4ecefec46f0eebdff27a465543fe3ab6f14b6a2876df636ebb9fc20a02ebfbb1695a04d50197c80b7678cc513222b
7
- data.tar.gz: 243833c66d4dc6a3eb952a53610226cf28c5f8d94b49c77b95d71737d33ec35ef32bafd3ebda38511b96be36fda8cc9ac59cc71ff47ae958940bd5401f6af2a5
6
+ metadata.gz: b361d425d87505bab75a23f84a9e8073b90a551d3aeffe33b39cae270dbb49a7925ea9bc90c66e553bc9c2bf6acc092732bc93998e7c1228f7b2c47a873308e8
7
+ data.tar.gz: d2bf943a2fa7e5a9693cb52bbb4ccce40f267b3b90c97fdc99050c890eb03e93395269f04f9ab752560e43667cc362c1c02abb677eb8bc4bd7c11241d231a756
@@ -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)
@@ -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 }
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  class Kalculator
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
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.1
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-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rltk