parsecs 0.2.19 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e7b3b272aa00c84d85c8ed2e54564840f6cda8d34865125a7e2b47eb2313946
4
- data.tar.gz: 9a0eca31231d8dbcd6d5006e0e0c3e1de8d008e4cf5d6891a50af7fd25924c01
3
+ metadata.gz: baad050f7884ccde189b53870ea8b12919bf9814c389677794119e64590b0c37
4
+ data.tar.gz: f46692c9899acb7993f103a223dfd2c8c582defba944c23b19bae345bbeda45e
5
5
  SHA512:
6
- metadata.gz: 5e9a252ffde2b57982a3bd68491d144514af414ff7bc5235002b914ecae0a11eff42a95db1acc22b5acb4e81165d6cf80f5f04f1379733f221ae4955c54a5327
7
- data.tar.gz: b1709ff79e5870d03c1579ec717d5ef9c932838fecbee26cb3e5c132b168e606a35c8a2cd6302ff6aef38062c3708a59abf605a13b3f305bc4ae890d962584f1
6
+ metadata.gz: f7b5293ef8325c2dffed4e73ec8957fcaf5e5f6ebe25ccfd9c3b2b44d1f0869c25324ca336da667fba9b4d0e82ba79ddb39d4a252371746b87d9e6bad69d19a4
7
+ data.tar.gz: 57759958a8205ca77b00f8ff62629e6023aaf81e14c9a3d4cbfaf14404c7473909839e474ba16168b332746e3d72188669fc4591def308c73b76b66e61534297
@@ -20,8 +20,8 @@ extern std::string native_direct_eval(std::string input);
20
20
  switch (*$2) {
21
21
  case 'i': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("int")); break;
22
22
  case 'f': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("float")); break;
23
- case 's': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("string")); break;
24
23
  case 'b': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("boolean")); break;
24
+ case 's': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("string")); break;
25
25
  case 'c': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("complex")); break;
26
26
  case 'm': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("matrix")); break;
27
27
  }
@@ -6,36 +6,43 @@ module Parsec
6
6
  class Parsec
7
7
  using StringToBooleanRefinements
8
8
 
9
- VERSION = '0.2.19'.freeze
9
+ VERSION = '0.2.20'.freeze
10
10
 
11
11
  # evaluates the equation
12
12
  def self.eval_equation(equation)
13
- remove_spaces(equation)
13
+ remove(equation, true)
14
14
 
15
15
  convert(Libnativemath.native_eval(equation))
16
16
  end
17
17
 
18
18
  # returns true or raise an error
19
- def self.validate_syntax(equation)
19
+ def self.validate_syntax!(equation)
20
+ remove(equation)
21
+
20
22
  validate(Libnativemath.native_eval(equation), true)
21
23
  end
22
24
 
23
25
  # returns true or an error string
24
- def self.verify_syntax(equation)
26
+ def self.validate_syntax(equation)
27
+ remove(equation)
28
+
25
29
  validate(Libnativemath.native_eval(equation), false)
26
30
  end
27
31
 
28
32
  private_class_method
29
33
 
30
- def self.remove_spaces(equation)
31
- # This line removes all spaces that are not between quotation marks
32
- # https://stackoverflow.com/questions/205521/using-regex-to-replace-all-spaces-not-in-quotes-in-ruby?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
33
- equation.gsub!(/( |(".*?"))/, '\\2')
34
+ def self.remove(equation, new_line = false)
35
+ equation.gsub!(/[\n\t\r]/, ' ')
36
+
37
+ # The following regex remove all spaces that are not between quot marks
38
+ # https://goo.gl/exJ66Y
39
+ equation.gsub!(/( |(".*?"))/, '\\2') if new_line == true
34
40
  end
35
41
 
36
42
  def self.convert(ans)
37
43
  case ans['value']
38
44
  when 'inf' then return 'Infinity'
45
+ when '-inf' then return '-Infinity'
39
46
  when 'nan' then return ans['value']
40
47
  end
41
48
 
@@ -44,7 +51,8 @@ module Parsec
44
51
  when 'float' then return ans['value'].to_f
45
52
  when 'boolean' then return ans['value'].to_bool
46
53
  when 'string' then return error_check(ans['value'])
47
- when 'c' then return 'complex number'
54
+ when 'complex' then return 'complex number' # Maybe future implementation
55
+ when 'matrix' then return 'matrix value' # Maybe future implementation
48
56
  end
49
57
  end
50
58
 
@@ -83,4 +83,22 @@ class TestParsec < Minitest::Test
83
83
  assert_equal(5, parsec.eval_equation('round(4.62)'))
84
84
  assert_equal(4.63, parsec.eval_equation('round_decimal(4.625, 2)'))
85
85
  end
86
+
87
+ def test_newlines_remotion
88
+ parsec = Parsec::Parsec
89
+ assert_equal(true, parsec.validate_syntax("4 + \n 2"))
90
+ assert_equal(true, parsec.validate_syntax("\n4\n+ \n 2\n"))
91
+ end
92
+
93
+ def test_validate_syntax
94
+ parsec = Parsec::Parsec
95
+ assert_equal(true, parsec.validate_syntax('((0.09/1.0)+2.58)-1.6+'))
96
+ assert_equal('Missing parenthesis.', parsec.validate_syntax('(0.09/1.0'))
97
+ end
98
+
99
+ def test_validate_syntax!
100
+ parsec = Parsec::Parsec
101
+ assert_equal(true, parsec.validate_syntax!('((0.09/1.0)+2.58)-1.6+'))
102
+ assert_raises(parsec.validate_syntax!('(0.09/1.0'))
103
+ end
86
104
  end
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.2.19
4
+ version: 0.2.20
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: 2018-06-05 00:00:00.000000000 Z
13
+ date: 2018-06-19 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.6
85
+ rubygems_version: 2.7.3
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: A gem to evaluate equations using muparserx C++ library