excel_to_code 0.2.22 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98a30a4502c1cb0068615b80e1b05cd68f4e1dee
|
4
|
+
data.tar.gz: 27283677b8603cbcbb40f7995a71de4713ae17dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e8e0cb3094aea477cb3e8af859a6005b9a44ae693d3869ef35a2ac4a2065c58c7f143d3700cb119dccef87bf940f40ac7fde0c5351bf31203b39c44079361d3
|
7
|
+
data.tar.gz: 063a30d831f861cb7f7faa403c4a49b4da2248b32e6c3aa3c74661d58c3020f1864fc85b15915711446c48336d4072f2683346406f5dfcd7e05ac0fbd43f65c9
|
@@ -41,7 +41,11 @@ module ExcelFunctions
|
|
41
41
|
when String
|
42
42
|
check_value.downcase == required_value.downcase
|
43
43
|
when Numeric
|
44
|
-
|
44
|
+
begin
|
45
|
+
Float(check_value) == required_value.to_f
|
46
|
+
rescue ArgumentError
|
47
|
+
false
|
48
|
+
end
|
45
49
|
else
|
46
50
|
check_value.downcase == required_value.to_s.downcase
|
47
51
|
end
|
data/src/excel_to_code.rb
CHANGED
@@ -176,10 +176,20 @@ class AstExpandArrayFormulae
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def array?(*args)
|
179
|
-
args.any? { |a| a.first == :array }
|
179
|
+
args.any? { |a| a.first == :array || function_that_returns_an_array?(a) }
|
180
|
+
end
|
181
|
+
|
182
|
+
def function_that_returns_an_array?(ast)
|
183
|
+
return false unless ast[0] == :function
|
184
|
+
return false unless ast[1] == :INDEX
|
185
|
+
return false if ast.length < 4
|
186
|
+
return false if (ast[3][0] == :number && ast[3][1].to_f != 0.0) && (ast[4][0] == :number && ast[4][1].to_f != 0.0)
|
187
|
+
# Might contain a zero or null for the row or column number
|
188
|
+
true
|
180
189
|
end
|
181
190
|
|
182
191
|
def array_ast_to_ruby_array(array_ast)
|
192
|
+
return function_to_ruby_array(array_ast) if function_that_returns_an_array?(array_ast)
|
183
193
|
return [[array_ast]] unless array_ast.first == :array
|
184
194
|
array_ast[1..-1].map do |row_ast|
|
185
195
|
row_ast[1..-1].map do |cell|
|
@@ -187,5 +197,20 @@ class AstExpandArrayFormulae
|
|
187
197
|
end
|
188
198
|
end
|
189
199
|
end
|
200
|
+
|
201
|
+
# This handles the special case of INDEX which might return an array
|
202
|
+
def function_to_ruby_array(ast)
|
203
|
+
return [[ast]] unless ast[0] == :function && ast[1] == :INDEX
|
204
|
+
return [[ast]] unless ast[2][0] == :array
|
205
|
+
rows = ast[2].length - 1
|
206
|
+
columns = ast[2][1].length - 1
|
207
|
+
array = Array.new(rows) { Array.new(columns) }
|
208
|
+
1.upto(rows).each do |row|
|
209
|
+
1.upto(columns).each do |column|
|
210
|
+
array[row-1][column-1] = [:function, :INDEX, ast, [:number, row], [:number, column]]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
array
|
214
|
+
end
|
190
215
|
|
191
216
|
end
|
@@ -202,6 +202,8 @@ class MapFormulaeToValues
|
|
202
202
|
indexes = @calculator._filtered_range_indexes(sum_range, *values)
|
203
203
|
if indexes.is_a?(Symbol)
|
204
204
|
new_ast = value(filtered_range)
|
205
|
+
elsif indexes.empty?
|
206
|
+
new_ast = [:number, 0]
|
205
207
|
else
|
206
208
|
new_ast = [:function, :SUM, *sum_range.values_at(*indexes)]
|
207
209
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excel_to_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|