kalculator 0.5.2 → 0.5.3

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: 4fd2684ec05188a764da05fae5593566ab7122191864da22ae2296b89d8e1185
4
- data.tar.gz: d4f25af127744abcfe43f13281169374cd678ec9964c96b0f365bbf8de69762c
3
+ metadata.gz: 9f7ebb299d556d90d2850064b9a43ba651c76e68f0517987600a7f9a05692fc6
4
+ data.tar.gz: 7736da10b84c6ef664c2ec29d67848f1247a11272e61400c0bca7e33e8f4ac2e
5
5
  SHA512:
6
- metadata.gz: b361d425d87505bab75a23f84a9e8073b90a551d3aeffe33b39cae270dbb49a7925ea9bc90c66e553bc9c2bf6acc092732bc93998e7c1228f7b2c47a873308e8
7
- data.tar.gz: d2bf943a2fa7e5a9693cb52bbb4ccce40f267b3b90c97fdc99050c890eb03e93395269f04f9ab752560e43667cc362c1c02abb677eb8bc4bd7c11241d231a756
6
+ metadata.gz: 94d5a135534cac641fa0ddc8308fc3b23d3d116eb068923573eef1257e1c4f124fa8c948301637157d696f729277965ffb06c36660ae4a191c4429406954f40f
7
+ data.tar.gz: b69f39bf645389c8ece99cc4e701c0da81dc470ed5a10f9045090b41b06656644d33f6127f17efdf55917c9ca70044353072492c445a3c2438d046c4c49bf613
@@ -90,6 +90,22 @@ class Kalculator
90
90
  expressions.map{|expression| evaluate(expression) }
91
91
  end
92
92
 
93
+ def max(_, left, right)
94
+ left = evaluate(left)
95
+ right = evaluate(right)
96
+ raise TypeError, "max only works with numbers, got #{left.inspect}" unless left.is_a?(Numeric)
97
+ raise TypeError, "max only works with numbers, got #{right.inspect}" unless right.is_a?(Numeric)
98
+ [left, right].max
99
+ end
100
+
101
+ def min(_, left, right)
102
+ left = evaluate(left)
103
+ right = evaluate(right)
104
+ raise TypeError, "min only works with numbers, got #{left.inspect}" unless left.is_a?(Numeric)
105
+ raise TypeError, "min only works with numbers, got #{right.inspect}" unless right.is_a?(Numeric)
106
+ [left, right].min
107
+ end
108
+
93
109
  def not(_, expression)
94
110
  bool = evaluate(expression)
95
111
  raise TypeError, "! only works with booleans, got #{bool.inspect}" unless bool === true || bool === false
@@ -25,6 +25,8 @@ class Kalculator
25
25
  rule(/contains/) { |t| :CONTAINS }
26
26
  rule(/count/) { |t| :COUNT }
27
27
  rule(/if/) { |t| :IF }
28
+ rule(/max/) { |t| :MAX }
29
+ rule(/min/) { |t| :MIN }
28
30
  rule(/sum/) { |t| :SUM }
29
31
  rule(/true/) { |t| :TRUE }
30
32
  rule(/false/) { |t| :FALSE }
@@ -19,6 +19,8 @@ class Kalculator
19
19
  clause('COUNT LPAREN expression RPAREN') do |_, _, e0, _|
20
20
  [:count, e0]
21
21
  end
22
+ clause('MAX LPAREN expression COMMA expression RPAREN') { |_, _, left, _, right, _| [:max, left, right] }
23
+ clause('MIN LPAREN expression COMMA expression RPAREN') { |_, _, left, _, right, _| [:min, left, right] }
22
24
  clause('LPAREN expression RPAREN') { |_, expression, _| expression }
23
25
  clause('LBRACKET expressions RBRACKET') { |_, expressions, _| [:list, expressions] }
24
26
 
@@ -1,3 +1,3 @@
1
1
  class Kalculator
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
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.2
4
+ version: 0.5.3
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-05 00:00:00.000000000 Z
11
+ date: 2018-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rltk