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 +4 -4
- data/lib/kalculator/evaluator.rb +16 -0
- data/lib/kalculator/lexer.rb +2 -0
- data/lib/kalculator/parser.rb +2 -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: 9f7ebb299d556d90d2850064b9a43ba651c76e68f0517987600a7f9a05692fc6
|
4
|
+
data.tar.gz: 7736da10b84c6ef664c2ec29d67848f1247a11272e61400c0bca7e33e8f4ac2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d5a135534cac641fa0ddc8308fc3b23d3d116eb068923573eef1257e1c4f124fa8c948301637157d696f729277965ffb06c36660ae4a191c4429406954f40f
|
7
|
+
data.tar.gz: b69f39bf645389c8ece99cc4e701c0da81dc470ed5a10f9045090b41b06656644d33f6127f17efdf55917c9ca70044353072492c445a3c2438d046c4c49bf613
|
data/lib/kalculator/evaluator.rb
CHANGED
@@ -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
|
data/lib/kalculator/lexer.rb
CHANGED
data/lib/kalculator/parser.rb
CHANGED
@@ -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
|
|
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.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-
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rltk
|