eqn 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +6 -0
- data/lib/eqn/calculator.rb +7 -4
- data/lib/eqn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15427350b2000655804633ff9ff5726c2f7a958b
|
4
|
+
data.tar.gz: f2a1cd9cce250a52ab4c1fa4dae75ddf0da118ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0e5afed9c04afcf453247fd648f8ddd902a03f3dc9605d911604512057e9c30b3049e571100743f6624d6cf07c038a3165b3fa1627fabcf579652607816195
|
7
|
+
data.tar.gz: 8750c30884c3c5e09f3a13cd69dfa6b39a82b7581bf935a14ee4db35d6da208b0b66686d1ec5d13af781ee587ff7d71af36963b470f423ae29180e500f67b46d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
data/README.md
CHANGED
@@ -66,6 +66,12 @@ If you need distinct equations with variable sets, you can instantiate separate
|
|
66
66
|
$ calc_two = Eqn::Calculator.new('1 + abc', abc: 5.0)
|
67
67
|
$ calc_two.calc
|
68
68
|
# => 6.0
|
69
|
+
$ calc_two.set(:abc, 3.0)
|
70
|
+
$ calc_two.calc
|
71
|
+
# => 4.0
|
72
|
+
$ calc_two.set(abc: 4.0)
|
73
|
+
$ calc_two.calc
|
74
|
+
# => 5.0
|
69
75
|
|
70
76
|
### Functions
|
71
77
|
|
data/lib/eqn/calculator.rb
CHANGED
@@ -5,8 +5,12 @@ module Eqn
|
|
5
5
|
@vars = vars
|
6
6
|
end
|
7
7
|
|
8
|
-
def set(
|
9
|
-
|
8
|
+
def set(key_or_hash, value = nil)
|
9
|
+
if key_or_hash.is_a?(Hash)
|
10
|
+
@vars.merge!(key_or_hash)
|
11
|
+
else
|
12
|
+
@vars[key_or_hash.intern] = value
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def method_missing(method)
|
@@ -16,14 +20,13 @@ module Eqn
|
|
16
20
|
|
17
21
|
class << self
|
18
22
|
def calculate(data, vars = {})
|
19
|
-
@@cache_vars = @@vars if defined?(@@vars)
|
20
23
|
@@vars = vars
|
21
24
|
begin
|
22
25
|
result = Parser.parse(data).value
|
23
26
|
raise ZeroDivisionError if result.is_a?(Float) && (result.abs == Float::INFINITY || result.nan?)
|
24
27
|
result
|
25
28
|
ensure
|
26
|
-
@@vars =
|
29
|
+
@@vars = nil
|
27
30
|
end
|
28
31
|
end
|
29
32
|
alias calc calculate
|
data/lib/eqn/version.rb
CHANGED