hesabu 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +45 -37
- data/bin/hesabucli +0 -0
- data/hesabu.gemspec +2 -1
- data/lib/hesabu.rb +3 -2
- data/lib/hesabu/multi_json.rb +65 -0
- data/lib/hesabu/solver.rb +3 -5
- data/lib/hesabu/version.rb +1 -1
- metadata +19 -5
- data/lib/hesabu/equation_cleaner.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9372fc461d5c52778243585448ddde3c5f5e51e8305bd0f9611e44f925703368
|
4
|
+
data.tar.gz: c1134317005e8f75b3ce98e020131cb81300748ab1246e075e0b495c62f3e6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f777c09c72a305645acccf4c376484bfb4c958392b1528f629221adca39b2df8d2703fa0b0890f41b7aa9446a5cacb83a8d06f7d40050295846c50b3bb371cc
|
7
|
+
data.tar.gz: 923eefff5ceb4a10f7ec54514d05b444fd30d4a9b353d6c7eb70eda2b8823882149369fab831a2b6a4ae5b40852a5fe46bb1d75c1bdaa87da71ddac89973dd82
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hesabu (0.1.
|
4
|
+
hesabu (0.1.14)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -11,30 +11,36 @@ GEM
|
|
11
11
|
ast (2.4.0)
|
12
12
|
byebug (10.0.2)
|
13
13
|
diff-lcs (1.3)
|
14
|
-
docile (1.3.
|
14
|
+
docile (1.3.1)
|
15
15
|
erubis (2.7.0)
|
16
|
-
faraday (0.
|
16
|
+
faraday (0.15.4)
|
17
17
|
multipart-post (>= 1.2, < 3)
|
18
|
-
flay (2.
|
18
|
+
flay (2.12.0)
|
19
19
|
erubis (~> 2.7.0)
|
20
20
|
path_expander (~> 1.0)
|
21
21
|
ruby_parser (~> 3.0)
|
22
22
|
sexp_processor (~> 4.0)
|
23
|
-
gitlab (4.
|
24
|
-
httparty
|
25
|
-
terminal-table
|
26
|
-
httparty (0.16.
|
23
|
+
gitlab (4.8.0)
|
24
|
+
httparty (>= 0.14.0)
|
25
|
+
terminal-table (>= 1.5.1)
|
26
|
+
httparty (0.16.3)
|
27
|
+
mime-types (~> 3.0)
|
27
28
|
multi_xml (>= 0.5.2)
|
29
|
+
jaro_winkler (1.5.2)
|
28
30
|
json (2.1.0)
|
31
|
+
mime-types (3.2.2)
|
32
|
+
mime-types-data (~> 3.2015)
|
33
|
+
mime-types-data (3.2018.0812)
|
29
34
|
multi_xml (0.6.0)
|
30
35
|
multipart-post (2.0.0)
|
31
|
-
octokit (4.
|
36
|
+
octokit (4.13.0)
|
32
37
|
sawyer (~> 0.8.0, >= 0.5.3)
|
33
|
-
|
34
|
-
|
38
|
+
oj (3.7.8)
|
39
|
+
parallel (1.13.0)
|
40
|
+
parser (2.6.0.0)
|
35
41
|
ast (~> 2.4.0)
|
36
|
-
path_expander (1.0.
|
37
|
-
powerpack (0.1.
|
42
|
+
path_expander (1.0.3)
|
43
|
+
powerpack (0.1.2)
|
38
44
|
pronto (0.9.5)
|
39
45
|
gitlab (~> 4.0, >= 4.0.0)
|
40
46
|
httparty (>= 0.13.7)
|
@@ -45,45 +51,46 @@ GEM
|
|
45
51
|
pronto-flay (0.9.0)
|
46
52
|
flay (~> 2.8)
|
47
53
|
pronto (~> 0.9.0)
|
48
|
-
pronto-rubocop (0.9.
|
54
|
+
pronto-rubocop (0.9.1)
|
49
55
|
pronto (~> 0.9.0)
|
50
|
-
rubocop (~> 0.
|
51
|
-
pronto-simplecov (0.1.
|
56
|
+
rubocop (~> 0.50, >= 0.49.1)
|
57
|
+
pronto-simplecov (0.1.1)
|
52
58
|
pronto (~> 0.9.0)
|
53
59
|
simplecov
|
54
|
-
public_suffix (3.0.
|
60
|
+
public_suffix (3.0.3)
|
55
61
|
rainbow (2.2.2)
|
56
62
|
rake
|
57
63
|
rake (10.5.0)
|
58
|
-
rspec (3.
|
59
|
-
rspec-core (~> 3.
|
60
|
-
rspec-expectations (~> 3.
|
61
|
-
rspec-mocks (~> 3.
|
62
|
-
rspec-core (3.
|
63
|
-
rspec-support (~> 3.
|
64
|
-
rspec-expectations (3.
|
64
|
+
rspec (3.8.0)
|
65
|
+
rspec-core (~> 3.8.0)
|
66
|
+
rspec-expectations (~> 3.8.0)
|
67
|
+
rspec-mocks (~> 3.8.0)
|
68
|
+
rspec-core (3.8.0)
|
69
|
+
rspec-support (~> 3.8.0)
|
70
|
+
rspec-expectations (3.8.2)
|
65
71
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
-
rspec-support (~> 3.
|
67
|
-
rspec-mocks (3.
|
72
|
+
rspec-support (~> 3.8.0)
|
73
|
+
rspec-mocks (3.8.0)
|
68
74
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-support (3.
|
71
|
-
rubocop (0.
|
75
|
+
rspec-support (~> 3.8.0)
|
76
|
+
rspec-support (3.8.0)
|
77
|
+
rubocop (0.63.1)
|
78
|
+
jaro_winkler (~> 1.5.1)
|
72
79
|
parallel (~> 1.10)
|
73
|
-
parser (>= 2.5)
|
80
|
+
parser (>= 2.5, != 2.5.1.1)
|
74
81
|
powerpack (~> 0.1)
|
75
82
|
rainbow (>= 2.2.2, < 4.0)
|
76
83
|
ruby-progressbar (~> 1.7)
|
77
|
-
unicode-display_width (~> 1.
|
84
|
+
unicode-display_width (~> 1.4.0)
|
78
85
|
ruby-prof (0.17.0)
|
79
|
-
ruby-progressbar (1.
|
80
|
-
ruby_parser (3.
|
86
|
+
ruby-progressbar (1.10.0)
|
87
|
+
ruby_parser (3.12.0)
|
81
88
|
sexp_processor (~> 4.9)
|
82
|
-
rugged (0.27.
|
89
|
+
rugged (0.27.7)
|
83
90
|
sawyer (0.8.1)
|
84
91
|
addressable (>= 2.3.5, < 2.6)
|
85
92
|
faraday (~> 0.8, < 1.0)
|
86
|
-
sexp_processor (4.
|
93
|
+
sexp_processor (4.11.0)
|
87
94
|
simplecov (0.16.1)
|
88
95
|
docile (~> 1.1)
|
89
96
|
json (>= 1.8, < 3)
|
@@ -92,7 +99,7 @@ GEM
|
|
92
99
|
terminal-table (1.8.0)
|
93
100
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
94
101
|
thor (0.19.4)
|
95
|
-
unicode-display_width (1.
|
102
|
+
unicode-display_width (1.4.1)
|
96
103
|
|
97
104
|
PLATFORMS
|
98
105
|
ruby
|
@@ -101,6 +108,7 @@ DEPENDENCIES
|
|
101
108
|
bundler (~> 1.16)
|
102
109
|
byebug
|
103
110
|
hesabu!
|
111
|
+
oj
|
104
112
|
pronto
|
105
113
|
pronto-flay
|
106
114
|
pronto-rubocop
|
@@ -111,4 +119,4 @@ DEPENDENCIES
|
|
111
119
|
simplecov
|
112
120
|
|
113
121
|
BUNDLED WITH
|
114
|
-
1.
|
122
|
+
1.17.1
|
data/bin/hesabucli
CHANGED
Binary file
|
data/hesabu.gemspec
CHANGED
@@ -28,10 +28,11 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
|
30
30
|
spec.add_development_dependency "byebug"
|
31
|
+
spec.add_development_dependency "oj"
|
31
32
|
spec.add_development_dependency "pronto"
|
32
33
|
spec.add_development_dependency "pronto-flay"
|
33
34
|
spec.add_development_dependency "pronto-rubocop"
|
34
35
|
spec.add_development_dependency "pronto-simplecov"
|
35
|
-
spec.add_development_dependency "simplecov"
|
36
36
|
spec.add_development_dependency "ruby-prof"
|
37
|
+
spec.add_development_dependency "simplecov"
|
37
38
|
end
|
data/lib/hesabu.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
1
|
+
require_relative "./hesabu/version"
|
2
2
|
|
3
3
|
require_relative "./hesabu/errors"
|
4
4
|
require_relative "./hesabu/types/numeric"
|
5
5
|
|
6
|
-
require_relative "./hesabu/
|
6
|
+
require_relative "./hesabu/multi_json"
|
7
7
|
require_relative "./hesabu/solver"
|
8
8
|
|
9
|
+
|
9
10
|
module Hesabu
|
10
11
|
HESABUCLI = File.expand_path("../bin/hesabucli", File.dirname(__FILE__))
|
11
12
|
puts "************** HESABU cli location : " + HESABUCLI
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Hesabu
|
2
|
+
# A wrapper to support both `oj` and normal `json`
|
3
|
+
#
|
4
|
+
# `oj` has some characteristics which make a very good candidate to
|
5
|
+
# be the preferred JSON parser for Hesabu. Mainly, it's fast, and it
|
6
|
+
# stays fast for large payloads.
|
7
|
+
#
|
8
|
+
# This module will check if `oj` is available and otherwise fall
|
9
|
+
# back to the regular JSON from the standard lib
|
10
|
+
#
|
11
|
+
# Hesabu::MultiJSON::generate(object) # Generate JSON
|
12
|
+
# Hesabu::MultiJSON::parse(string) # Parse JSON
|
13
|
+
module MultiJSON
|
14
|
+
# Takes a ruby object and transforms it to JSON.
|
15
|
+
def self.generate(object)
|
16
|
+
_fast_to_json(object)
|
17
|
+
rescue NameError
|
18
|
+
define_fast_json(Hesabu::MultiJSON, "to_json")
|
19
|
+
_fast_to_json(object)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Takes a string (hopefully containing JSON) and parses it to Ruby
|
23
|
+
def self.parse(string)
|
24
|
+
_fast_from_json(string)
|
25
|
+
rescue NameError
|
26
|
+
define_fast_json(Hesabu::MultiJSON, "from_json")
|
27
|
+
_fast_from_json(string)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.to_json_method
|
31
|
+
body = begin
|
32
|
+
require "oj"
|
33
|
+
%(::Oj.dump(object, mode: :compat, time_format: :ruby, use_to_json: true))
|
34
|
+
rescue LoadError
|
35
|
+
%(JSON.fast_generate(object, create_additions: false, quirks_mode: true))
|
36
|
+
end
|
37
|
+
<<~METHOD
|
38
|
+
def _fast_to_json(object)
|
39
|
+
#{body}
|
40
|
+
end
|
41
|
+
METHOD
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.from_json_method
|
45
|
+
body = begin
|
46
|
+
require "oj"
|
47
|
+
%(::Oj.load(string, mode: :compat, time_format: :ruby, use_to_json: true))
|
48
|
+
rescue LoadError
|
49
|
+
%(JSON.parse(string, create_additions: false))
|
50
|
+
end
|
51
|
+
<<~METHOD
|
52
|
+
def _fast_from_json(string)
|
53
|
+
#{body}
|
54
|
+
end
|
55
|
+
METHOD
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.define_fast_json(receiver, name)
|
59
|
+
cl = caller_locations(1..1).first
|
60
|
+
method_body = public_send("#{name}_method")
|
61
|
+
warn "Defining #{receiver}._fast_#{name} as #{method_body.inspect}"
|
62
|
+
receiver.instance_eval method_body, cl.absolute_path, cl.lineno
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/hesabu/solver.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Hesabu
|
4
2
|
class Solver
|
5
3
|
def initialize
|
@@ -10,18 +8,18 @@ module Hesabu
|
|
10
8
|
if raw_expression.nil? || name.nil?
|
11
9
|
raise Hesabu::ArgumentError, "name or expression can't be nil : '#{name}', '#{raw_expression}'"
|
12
10
|
end
|
13
|
-
@equations[name] =
|
11
|
+
@equations[name] = raw_expression.to_s
|
14
12
|
end
|
15
13
|
|
16
14
|
def solve!
|
17
15
|
return {} if @equations.empty?
|
18
16
|
result = nil
|
19
17
|
IO.popen(HESABUCLI, mode = "r+") do |io|
|
20
|
-
io.write @equations
|
18
|
+
io.write Hesabu::MultiJSON.generate(@equations)
|
21
19
|
io.close_write # let the process know you've given it all the data
|
22
20
|
result = io.read
|
23
21
|
end
|
24
|
-
solution =
|
22
|
+
solution = Hesabu::MultiJSON.parse(result)
|
25
23
|
exit_status = $CHILD_STATUS.exitstatus
|
26
24
|
|
27
25
|
log_everything(exit_status, result) if ENV["HESABU_DEBUG"] || exit_status != 0
|
data/lib/hesabu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hesabu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stéphan Mestach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oj
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: pronto
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +137,7 @@ dependencies:
|
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
140
|
+
name: ruby-prof
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
@@ -137,7 +151,7 @@ dependencies:
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: simplecov
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
@@ -175,8 +189,8 @@ files:
|
|
175
189
|
- bin/setup
|
176
190
|
- hesabu.gemspec
|
177
191
|
- lib/hesabu.rb
|
178
|
-
- lib/hesabu/equation_cleaner.rb
|
179
192
|
- lib/hesabu/errors.rb
|
193
|
+
- lib/hesabu/multi_json.rb
|
180
194
|
- lib/hesabu/solver.rb
|
181
195
|
- lib/hesabu/types/numeric.rb
|
182
196
|
- lib/hesabu/version.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
module Hesabu
|
3
|
-
class EquationCleaner
|
4
|
-
def self.clean(eq)
|
5
|
-
return eq if !eq.include?("AND") && !eq.include?("=") && !eq.include?("OR")
|
6
|
-
clean_eq = eq.gsub(" AND ", " && ")
|
7
|
-
clean_eq = clean_eq.gsub(" OR ", " || ")
|
8
|
-
clean_eq.split(/(<=|>=|!=|==|=|\*|\s)/m)
|
9
|
-
.map { |a| a == "=" ? "==" : a }
|
10
|
-
.join("")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|