soroban 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +15 -7
- data/Soroban.gemspec +3 -1
- data/VERSION +1 -1
- data/files/Physics.xlsx +0 -0
- data/lib/soroban/cell.rb +2 -0
- data/lib/soroban/functions/vlookup.rb +7 -4
- data/lib/soroban/helpers.rb +1 -1
- data/lib/soroban/import/ruby_xl_importer.rb +0 -1
- data/lib/soroban/label_walker.rb +9 -3
- data/lib/soroban/parser/nodes.rb +1 -8
- data/spec/import_spec.rb +27 -0
- metadata +5 -3
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -40,7 +40,7 @@ puts s.C1 # => 50
|
|
40
40
|
Bindings
|
41
41
|
--------
|
42
42
|
|
43
|
-
Soroban allows you to bind meaningful variable names to individual cells and to ranges of cells. When bound to a range, variables act as an array
|
43
|
+
Soroban allows you to bind meaningful variable names to individual cells and to ranges of cells. When bound to a range, variables act as an array.
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
s.set(:A1 => 'hello', 'B1:B5' => [1,2,3,4,5])
|
@@ -77,7 +77,7 @@ s.set("D1:D5" => [1,2,3,4,5])
|
|
77
77
|
|
78
78
|
s.missing # => []
|
79
79
|
|
80
|
-
s.cells # => {
|
80
|
+
s.cells # => {:F1=>"= E1 + SUM(D1:D5)", :E1=>"= D1 ^ D2", :D1=>"1", :D2=>"2", :D3=>"3", :D4=>"4", :D5=>"5"}
|
81
81
|
```
|
82
82
|
|
83
83
|
Importers
|
@@ -86,17 +86,25 @@ Importers
|
|
86
86
|
Soroban has a built-in importer for xlsx files. It requires the [RubyXL](https://github.com/gilt/rubyXL) gem. Use it as follows:
|
87
87
|
|
88
88
|
```ruby
|
89
|
-
require 'rubyXL'
|
90
|
-
|
91
89
|
BINDINGS = {
|
92
|
-
:
|
90
|
+
:planet => :B1,
|
93
91
|
:mass => :B2,
|
94
|
-
:force => :
|
92
|
+
:force => :B3
|
95
93
|
}
|
96
94
|
|
97
|
-
s = Soroban::Import::rubyXL("/
|
95
|
+
s = Soroban::Import::rubyXL("files/Physics.xlsx", 0, BINDINGS )
|
96
|
+
|
97
|
+
s.planet = 'Earth'
|
98
|
+
s.mass = 80
|
99
|
+
puts s.force # => 783.459251241996
|
100
|
+
|
101
|
+
s.planet = 'Venus'
|
102
|
+
s.mass = 80
|
103
|
+
puts s.force # => 710.044826106394
|
98
104
|
```
|
99
105
|
|
106
|
+
The above example parses the first sheet of Physics.xlsx, which you can [download](https://github.com/agworld/soroban/raw/master/files/Physics.xlsx).
|
107
|
+
|
100
108
|
This import process returns a new Soroban::Sheet object that contains all the
|
101
109
|
cells required to calculate the values of the bound variables, and which has the
|
102
110
|
bindings set up correctly.
|
data/Soroban.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "soroban"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Hutchens"]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"Soroban.gemspec",
|
30
30
|
"VERSION",
|
31
|
+
"files/Physics.xlsx",
|
31
32
|
"lib/soroban.rb",
|
32
33
|
"lib/soroban/cell.rb",
|
33
34
|
"lib/soroban/error.rb",
|
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
|
|
54
55
|
"lib/soroban/sheet.rb",
|
55
56
|
"lib/soroban/value_walker.rb",
|
56
57
|
"spec/documentation_spec.rb",
|
58
|
+
"spec/import_spec.rb",
|
57
59
|
"spec/soroban_spec.rb",
|
58
60
|
"spec/spec_helper.rb"
|
59
61
|
]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/files/Physics.xlsx
ADDED
Binary file
|
data/lib/soroban/cell.rb
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
Soroban::define :VLOOKUP => lambda { |value, range, col, inexact|
|
4
4
|
fc, fr, tc, tr = Soroban::getRange(range)
|
5
5
|
i = walk("#{fc}#{fr}:#{fc}#{tr}").find_index(value)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if i.nil?
|
7
|
+
nil
|
8
|
+
else
|
9
|
+
(0...i).each { fr.next! }
|
10
|
+
(1...col).each { fc.next! }
|
11
|
+
eval("@#{fc}#{fr}.get")
|
12
|
+
end
|
10
13
|
}
|
data/lib/soroban/helpers.rb
CHANGED
@@ -41,7 +41,7 @@ module Soroban
|
|
41
41
|
def self.getPos(label)
|
42
42
|
# TODO: fix for labels such as "BC42"
|
43
43
|
match = /^([a-zA-Z]+)([\d]+)$/.match(label.to_s)
|
44
|
-
return match[2].to_i - 1, match[1].upcase[0]-"A"[0]
|
44
|
+
return match[2].to_i - 1, match[1].upcase[0].ord-"A"[0].ord
|
45
45
|
end
|
46
46
|
|
47
47
|
# Return an array of values for the supplied arguments (which may be numbers, labels and ranges).
|
data/lib/soroban/label_walker.rb
CHANGED
@@ -12,9 +12,15 @@ module Soroban
|
|
12
12
|
|
13
13
|
# Yield the label of each cell referenced by the supplied range.
|
14
14
|
def each
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
col, row = @fc, @fr
|
16
|
+
while true do
|
17
|
+
yield "#{col}#{row}"
|
18
|
+
break if row == @tr && col == @tc
|
19
|
+
if row == @tr
|
20
|
+
row = @fr
|
21
|
+
col = col.next
|
22
|
+
else
|
23
|
+
row = row.next
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
data/lib/soroban/parser/nodes.rb
CHANGED
@@ -51,14 +51,7 @@ module Soroban
|
|
51
51
|
"'#{value}'"
|
52
52
|
end
|
53
53
|
def extract(value)
|
54
|
-
|
55
|
-
retval = []
|
56
|
-
(fc..tc).each do |cc|
|
57
|
-
(fr..tr).each do |cr|
|
58
|
-
retval << "#{cc}#{cr}".to_sym
|
59
|
-
end
|
60
|
-
end
|
61
|
-
retval
|
54
|
+
LabelWalker.new(value).map { |label| "#{label}".to_sym }
|
62
55
|
end
|
63
56
|
end
|
64
57
|
|
data/spec/import_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Documentation", :if => Gem.available?("rubyXL") do
|
4
|
+
|
5
|
+
it "can import xlsx files using RubyXL" do
|
6
|
+
|
7
|
+
BINDINGS = {
|
8
|
+
:planet => :B1,
|
9
|
+
:mass => :B2,
|
10
|
+
:force => :B3
|
11
|
+
}
|
12
|
+
|
13
|
+
s = Soroban::Import::rubyXL("files/Physics.xlsx", 0, BINDINGS )
|
14
|
+
|
15
|
+
s.planet = 'Earth'
|
16
|
+
s.mass = 80
|
17
|
+
puts s.force # => 783.459251241996
|
18
|
+
s.force.should be_within(0.01).of(783.46)
|
19
|
+
|
20
|
+
s.planet = 'Venus'
|
21
|
+
s.mass = 80
|
22
|
+
puts s.force # => 710.044826106394
|
23
|
+
s.force.should be_within(0.01).of(710.04)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soroban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Hutchens
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- Rakefile
|
103
103
|
- Soroban.gemspec
|
104
104
|
- VERSION
|
105
|
+
- files/Physics.xlsx
|
105
106
|
- lib/soroban.rb
|
106
107
|
- lib/soroban/cell.rb
|
107
108
|
- lib/soroban/error.rb
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- lib/soroban/sheet.rb
|
129
130
|
- lib/soroban/value_walker.rb
|
130
131
|
- spec/documentation_spec.rb
|
132
|
+
- spec/import_spec.rb
|
131
133
|
- spec/soroban_spec.rb
|
132
134
|
- spec/spec_helper.rb
|
133
135
|
homepage: https://github.com/agworld/soroban
|