kalculator 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kalculator.rb +5 -0
- data/lib/kalculator/transform.rb +15 -0
- data/lib/kalculator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13f752f4822c544a9380ec994d5c5b82590b6978dd7941b71b094bf703966182
|
4
|
+
data.tar.gz: 34b593efc2ac447d573b42c0a55ae286587745d140890a67fcaba6251828352b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d422ae52ab12feaefcd11d62890a2237fb019acd8f4ff7f8654273bcaa6c8b78c574e4b8bb1646130e8e1f7bf9a70241a3055297c1d1956e770cfad83147115f
|
7
|
+
data.tar.gz: 5ababeb0c7d56779087bbb76832c11f9809d4eea954a993449e2e6022626690805aa1e26490092a8814c478aefa196bb8b301676829ef2a4c9bfdf45918c38b5
|
data/lib/kalculator.rb
CHANGED
@@ -6,6 +6,7 @@ require "kalculator/formula"
|
|
6
6
|
require "kalculator/lexer"
|
7
7
|
require "kalculator/nested_lookup"
|
8
8
|
require "kalculator/parser"
|
9
|
+
require "kalculator/transform"
|
9
10
|
require "kalculator/version"
|
10
11
|
|
11
12
|
class Kalculator
|
@@ -16,4 +17,8 @@ class Kalculator
|
|
16
17
|
def self.new(*args)
|
17
18
|
Kalculator::Formula.new(*args)
|
18
19
|
end
|
20
|
+
|
21
|
+
def self.parse(formula)
|
22
|
+
Kalculator::Parser.parse(Kalculator::Lexer.lex(formula))
|
23
|
+
end
|
19
24
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Kalculator
|
2
|
+
module Transform
|
3
|
+
def self.run(node, &block)
|
4
|
+
new_node = yield node
|
5
|
+
return new_node if is_terminal?(new_node)
|
6
|
+
args = new_node[1..-1].map{ |arg| run(arg, &block) }
|
7
|
+
args.unshift(new_node.first)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.is_terminal?(node)
|
11
|
+
return false if node.is_a?(Array) && node.first.is_a?(Symbol)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
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.4
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rltk
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/kalculator/lexer.rb
|
97
97
|
- lib/kalculator/nested_lookup.rb
|
98
98
|
- lib/kalculator/parser.rb
|
99
|
+
- lib/kalculator/transform.rb
|
99
100
|
- lib/kalculator/version.rb
|
100
101
|
homepage: https://github.com/mmmries/kalculator
|
101
102
|
licenses:
|