parsecs 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parsec.rb +15 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e039583b7643043c193e9eb735786c005cbfcf9dbcc7f39a97801dcb18efdaa0
4
- data.tar.gz: b62038b2ef3dada7ec48d0c225c192521285c095c1f28bbdeda034b5dd312309
3
+ metadata.gz: d4695aaa62f4e133872d9221c795666205cc147d91d1c05dcc60b40a938ed540
4
+ data.tar.gz: c86c2a15be806e8f5a3d6952b94426293214fc325b92a37e556181f48169fdaf
5
5
  SHA512:
6
- metadata.gz: 32a7cdb33747009332a88e765ac190647530e560d6bf0cacd5f74de37ee198f7bb5d2fb20e5ebbb40059d6d78f1de6640b480808b6933c76cb002411e3795955
7
- data.tar.gz: 410979de5ca0b234c0059d2ee0c269ccce78038f054ad3cce3f3dfa50f733815bd933c2f1dd365a8a1104f3eee2c3d5e93a6ba32ab41d7bbb486c403bc27d0ab
6
+ metadata.gz: b9a0cb09771ea71a24f2d5397935025bc88bbae6757bc6b6c24aeb18646ebea600afacace90a10b32d1dee4dae371ed49b6fd0499456f9fc4009483bfce19f65
7
+ data.tar.gz: 70b6e172a0e102e4a7678a2e9f3a1860e80cbe06018e66060213b1d47df222527a2daa0bb1d6aab3c22318daf6a2ff42196650513b7b1e267decb53575b32233
data/lib/parsec.rb CHANGED
@@ -6,16 +6,23 @@ module Parsec
6
6
  class Parsec
7
7
  using StringToBooleanRefinements
8
8
 
9
- VERSION = '0.2.16'.freeze
9
+ VERSION = '0.2.17'.freeze
10
10
 
11
+ # evaluates the equation
11
12
  def self.eval_equation(equation)
12
13
  remove_spaces(equation)
13
14
 
14
15
  convert(Libnativemath.native_eval(equation))
15
16
  end
16
17
 
18
+ # returns true or raise an error
17
19
  def self.validate_syntax(equation)
18
- validate(Libnativemath.native_eval(equation))
20
+ validate(Libnativemath.native_eval(equation), true)
21
+ end
22
+
23
+ # returns true or an error string
24
+ def self.verify_syntax(equation)
25
+ validate(Libnativemath.native_eval(equation), false)
19
26
  end
20
27
 
21
28
  private_class_method
@@ -36,19 +43,20 @@ module Parsec
36
43
  when 'int' then return ans['value'].to_i
37
44
  when 'float' then return ans['value'].to_f
38
45
  when 'boolean' then return ans['value'].to_bool
39
- when 'string' then return verify_string(ans['value'])
46
+ when 'string' then return syntax_check(ans['value'])
40
47
  when 'c' then return 'complex number'
41
48
  end
42
49
  end
43
50
 
44
- def self.verify_string(output)
45
- raise ArgumentError, output.sub('Error: ', '') if output.include?('Error')
51
+ def self.syntax_check(output)
52
+ raise SyntaxError, output.sub('Error: ', '') if output.include?('Error')
46
53
  output.delete('\"')
47
54
  end
48
55
 
49
- def self.validate(ans)
56
+ def self.validate(ans, raise_error)
50
57
  if (ans['type'] == 'string') && ans['value'].include?('Error: ')
51
- raise ArgumentError, ans['value'].sub('Error: ', '')
58
+ raise SyntaxError, ans['value'].sub('Error: ', '') if raise_error
59
+ return ans['value'].sub('Error: ', '')
52
60
  end
53
61
  true
54
62
  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.16
4
+ version: 0.2.17
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-05-25 00:00:00.000000000 Z
13
+ date: 2018-06-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest