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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f491689b423601f13d531240c70349c9af27d4ba39bcf0194771b415ffd567d
4
- data.tar.gz: 5d051aea5ed0a8538397084ca40c231e8fbc1a48297960d2598a3d21d1adf017
3
+ metadata.gz: c08485876a66a7be42dad44eae2787495ffa98447defb56b9c5fa9afdebf3c2e
4
+ data.tar.gz: 6e5a10133bd0aa4909bc58e0e2bf2d668638800fb80f17fa034406041eed1eb9
5
5
  SHA512:
6
- metadata.gz: b0925569b881e6d3d6ac92b19024b4f4e065248fd049c85516fb1e535627b0b267f940e26ef449b39441a0d3b894cf64b02f94fdc53040b80d3039ca65939acc
7
- data.tar.gz: 4dff210da8d09ace5f08df556ce49eaf48e2f511e395974853694276c18e7e044b233010ed26ae31c398664c8ff4edddaef486ab8084ee2e0904f1141d348a30
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 = '65ff99e53961d86f14d214e49154ae26c94ec221'.freeze
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.5.1'.freeze
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
- remove(equation, true)
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
- remove(equation)
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
- remove(equation)
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
- remove(equation, true)
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.remove(equation, new_line = false)
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.5.1
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-01 00:00:00.000000000 Z
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.3
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