parsecs 0.5.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libnativemath/extconf.rb +1 -1
- data/lib/parsec.rb +6 -6
- data/test/test_parsec.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c08485876a66a7be42dad44eae2787495ffa98447defb56b9c5fa9afdebf3c2e
|
4
|
+
data.tar.gz: 6e5a10133bd0aa4909bc58e0e2bf2d668638800fb80f17fa034406041eed1eb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 690e7b876e987b78f561e54b0d66edb4c45da9ddca09bc4253c33e6d4d7024f95212e803219b9debfae109f17d2aa094a304376ca84f32732caeaa37f167b07c
|
7
|
+
data.tar.gz: 5b77f2a67f728c21a792f12b6c43044936ab2eb5b391e41893921ca6d0c08c15c215651a00a546d0621f9710ae9152d51b680bb9f7e888901e385dd71c0bd8bf
|
@@ -38,7 +38,7 @@ libs.each do |lib|
|
|
38
38
|
end
|
39
39
|
|
40
40
|
GIT_REPOSITORY = 'https://github.com/niltonvasques/equations-parser.git'.freeze
|
41
|
-
COMMIT = '
|
41
|
+
COMMIT = 'a5ced9f1ce02a13f4eca138fa66c98a0e76775d6'.freeze
|
42
42
|
|
43
43
|
Dir.chdir(BASEDIR) do
|
44
44
|
system('git init')
|
data/lib/parsec.rb
CHANGED
@@ -6,7 +6,7 @@ module Parsec
|
|
6
6
|
class Parsec
|
7
7
|
using StringToBooleanRefinements
|
8
8
|
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.6.1'.freeze
|
10
10
|
|
11
11
|
# evaluates the equation and returns only the result
|
12
12
|
def self.eval_equation(equation)
|
@@ -15,7 +15,7 @@ module Parsec
|
|
15
15
|
|
16
16
|
# evaluates the equation and returns the result and its data type
|
17
17
|
def self.eval_equation_with_type(equation)
|
18
|
-
|
18
|
+
sanitize(equation, true)
|
19
19
|
|
20
20
|
result = Libnativemath.native_eval(equation)
|
21
21
|
{ value: convert(result), type: result['type'].to_sym }
|
@@ -23,20 +23,20 @@ module Parsec
|
|
23
23
|
|
24
24
|
# returns true or raise an error
|
25
25
|
def self.validate_syntax!(equation)
|
26
|
-
|
26
|
+
sanitize(equation)
|
27
27
|
|
28
28
|
validate(Libnativemath.native_eval(equation), true)
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns true or an error string
|
32
32
|
def self.validate_syntax(equation)
|
33
|
-
|
33
|
+
sanitize(equation)
|
34
34
|
|
35
35
|
validate(Libnativemath.native_eval(equation), false)
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.get_result_type(equation)
|
39
|
-
|
39
|
+
sanitize(equation, true)
|
40
40
|
|
41
41
|
result = Libnativemath.native_eval(equation)
|
42
42
|
result['type'].to_sym if validate(result, true)
|
@@ -44,7 +44,7 @@ module Parsec
|
|
44
44
|
|
45
45
|
private_class_method
|
46
46
|
|
47
|
-
def self.
|
47
|
+
def self.sanitize(equation, new_line = false)
|
48
48
|
equation.gsub!(/[\n\t\r]/, ' ')
|
49
49
|
|
50
50
|
# The following regex remove all spaces that are not between quot marks
|
data/test/test_parsec.rb
CHANGED
@@ -123,6 +123,21 @@ class TestParsec < Minitest::Test
|
|
123
123
|
assert_equal(1, parsec.eval_equation('daysdiff("2018-01-01", "2017-12-31")'))
|
124
124
|
end
|
125
125
|
|
126
|
+
def test_datetime_functions
|
127
|
+
parsec = Parsec::Parsec
|
128
|
+
assert_equal(24, parsec.eval_equation('hoursdiff("2018-01-01", "2018-01-02")'))
|
129
|
+
assert_equal(288, parsec.eval_equation('hoursdiff("2019-02-01", "2019-02-13")'))
|
130
|
+
assert_equal(4, parsec.eval_equation('hoursdiff("2019-02-01T08:00", "2019-02-01T12:00")'))
|
131
|
+
assert_equal(28, parsec.eval_equation('hoursdiff("2019-02-01T08:00", "2019-02-02T12:00")'))
|
132
|
+
assert_equal(3.67, parsec.eval_equation('hoursdiff("2019-02-01T08:20", "2019-02-01T12:00")'))
|
133
|
+
assert_equal(0, parsec.eval_equation('hoursdiff("2018-01-01", "2018-01-01")'))
|
134
|
+
assert_equal(-20, parsec.eval_equation('hoursdiff("2018-01-02T08:00", "2018-01-01T12:00")'))
|
135
|
+
assert_raises(SyntaxError) { parsec.eval_equation('hoursdiff("2018-01-01", "INVALID2")') }
|
136
|
+
assert_raises(SyntaxError) { parsec.eval_equation('hoursdiff("INVALID1", "2018-01-01")') }
|
137
|
+
assert_raises(SyntaxError) { parsec.eval_equation('hoursdiff("INVALID1", "INVALID2")') }
|
138
|
+
assert_raises(SyntaxError) { parsec.eval_equation('hoursdiff(2, 3)') }
|
139
|
+
end
|
140
|
+
|
126
141
|
def test_eval_equation_with_type
|
127
142
|
parsec = Parsec::Parsec
|
128
143
|
assert_equal({ value: 10, type: :int }, parsec.eval_equation_with_type('(5 + 1) + (6 - 2)'))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsecs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-03-
|
13
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -82,7 +82,7 @@ requirements:
|
|
82
82
|
- swig
|
83
83
|
- cmake
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.7.
|
85
|
+
rubygems_version: 2.7.7
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: A gem to evaluate equations using muparserx C++ library
|