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 +4 -4
- data/ext/libnativemath/extconf.rb +2 -0
- data/lib/parsec.rb +19 -4
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ad56548a4425c9d244cb1784f332a6508f59dcd2896655cc29a5f67d712a38
|
4
|
+
data.tar.gz: 6e1d77b803ee49b242ca7a079dc33c8696e10b56aef21c875f1f4b4d749c1af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
9
|
+
VERSION = '0.2.15'.freeze
|
10
10
|
|
11
11
|
def self.eval_equation(equation)
|
12
|
-
|
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.
|
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-
|
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:
|
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
|
-
-
|
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.
|
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
|