parsecs 0.2.14 → 0.2.15

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: 61b24503f941948f023ee022527c79b418cfe3186dcd769d2a38ab0df630ff37
4
- data.tar.gz: 2d7ad237ace66c7b8322b4c39c1e122a073a6a27f04ee55e7a0ccf02da62eef5
3
+ metadata.gz: 85ad56548a4425c9d244cb1784f332a6508f59dcd2896655cc29a5f67d712a38
4
+ data.tar.gz: 6e1d77b803ee49b242ca7a079dc33c8696e10b56aef21c875f1f4b4d749c1af4
5
5
  SHA512:
6
- metadata.gz: 574e305a618c0507f41c44fb79981bb16842e46ddedbaa053119c7fcadd45555c8f157008324a451e3d66a69ce8e09a8b40efa3783b808266f7b116b2323b037
7
- data.tar.gz: 9ba3a929a6bfbd8e62434f08226df0eee34c36b1f2386f5f44f4b33f5e25333d689f3b7f43eb1e839a5a2f6060844b158befbcc56faa0f1dae9eb6ccde05ab71
6
+ metadata.gz: f453f08f435ed987462013657deba16aa678a89962fcfdcc0bfdc6985c68bdb0845869e75f4647c5ac48223a2e8ace1d0640c0ffd959b9da24748c196f291dbf
7
+ data.tar.gz: 5f2c08d1c7017aaec6e78830bee6c7c87d2ca68caf03bc453d4324c195efa3fefe29cb9d6134a4a5cbba94f5d1958db68816e099227c21179bee5b7d5cc5fcd4
@@ -38,6 +38,8 @@ libs.each do |lib|
38
38
  end
39
39
 
40
40
  Dir.chdir(BASEDIR) do
41
+ system('git init')
42
+ system('git submodule add https://github.com/niltonvasques/equations-parser.git ext/equations-parser')
41
43
  system('git submodule update --init --recursive')
42
44
 
43
45
  Dir.chdir('ext/equations-parser/') do
data/lib/parsec.rb CHANGED
@@ -6,18 +6,26 @@ module Parsec
6
6
  class Parsec
7
7
  using StringToBooleanRefinements
8
8
 
9
- VERSION = '0.2.14'.freeze
9
+ VERSION = '0.2.15'.freeze
10
10
 
11
11
  def self.eval_equation(equation)
12
- # This line removes all spaces that are not between quotation marks
13
- # 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
14
- equation.gsub!(/( |(".*?"))/, '\\2')
12
+ remove_spaces(equation)
15
13
 
16
14
  convert(Libnativemath.native_eval(equation))
17
15
  end
18
16
 
17
+ def self.validate_syntax(equation)
18
+ validate(Libnativemath.native_eval(equation))
19
+ end
20
+
19
21
  private_class_method
20
22
 
23
+ def self.remove_spaces(equation)
24
+ # This line removes all spaces that are not between quotation marks
25
+ # 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
26
+ equation.gsub!(/( |(".*?"))/, '\\2')
27
+ end
28
+
21
29
  def self.convert(ans)
22
30
  case ans['value']
23
31
  when 'inf' then return 'Infinity'
@@ -37,5 +45,12 @@ module Parsec
37
45
  raise ArgumentError, output.sub('Error: ', '') if output.include?('Error')
38
46
  output.delete('\"')
39
47
  end
48
+
49
+ def self.validate(ans)
50
+ if (ans['type'] == 'string') && ans['value'].include?('Error: ')
51
+ raise ArgumentError, ans['value'].sub('Error: ', '')
52
+ end
53
+ true
54
+ end
40
55
  end
41
56
  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.14
4
+ version: 0.2.15
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-23 00:00:00.000000000 Z
13
+ date: 2018-05-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -40,7 +40,8 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '12.1'
43
- description: Parsecs
43
+ description: ParseCs is a gem to evaluate math formulas using a lighter and faster
44
+ version of the muparserx C++ library
44
45
  email:
45
46
  - nilton.vasques@gmail.com
46
47
  - victorcorcos@gmail.com
@@ -56,7 +57,7 @@ files:
56
57
  - test/test_parsec.rb
57
58
  homepage: https://github.com/niltonvasques/parsec
58
59
  licenses:
59
- - mit
60
+ - MIT
60
61
  metadata: {}
61
62
  post_install_message:
62
63
  rdoc_options: []
@@ -68,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
69
  requirements:
69
70
  - - ">="
70
71
  - !ruby/object:Gem::Version
71
- version: '0'
72
+ version: '2.0'
72
73
  required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  requirements:
74
75
  - - ">="
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  requirements: []
78
79
  rubyforge_project:
79
- rubygems_version: 2.7.6
80
+ rubygems_version: 2.7.3
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: A gem to evaluate math equations using a lighter and faster version of the