excel_to_code 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/commands/excel_to_x.rb +3 -1
- data/src/simplify.rb +1 -0
- data/src/simplify/replace_transpose_function.rb +34 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7529040ce2d0f45b5a280ac08be87c8ac0df7a73
|
4
|
+
data.tar.gz: dd33604aada1850a86209407453eab32c1562f5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6adb53e38ffcc2326755175551c358fe223288b2dcd4ac1d23a7c75eca43b785c780836e9dadf39beb15ef5124c896e74af3b69bd510a4dfd9a143153bb13e2a
|
7
|
+
data.tar.gz: 22b7b90bc550f925c704a4087a496ed2e0754a1f93ce0243ddedf5b38367c3b6d21b2e9d268c10d522651aff8e45cd2967606e3e461ff5c8bacb7c03b3af32d0
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -585,9 +585,10 @@ class ExcelToX
|
|
585
585
|
@replace_ranges_with_array_literals_replacer ||= ReplaceRangesWithArrayLiteralsAst.new
|
586
586
|
expand_array_formulae_replacer = AstExpandArrayFormulae.new
|
587
587
|
simplify_arithmetic_replacer ||= SimplifyArithmeticAst.new
|
588
|
+
@shared_string_replacer ||= ReplaceSharedStringAst.new(@shared_strings)
|
589
|
+
transpose_function_replacer = ReplaceTransposeFunction.new
|
588
590
|
|
589
591
|
# FIXME: THIS IS THE MOST HORRIFIC BODGE. I HATE IT.
|
590
|
-
@shared_string_replacer ||= ReplaceSharedStringAst.new(@shared_strings)
|
591
592
|
emergency_indirect_replacement_bodge = EmergencyArrayFormulaReplaceIndirectBodge.new
|
592
593
|
emergency_indirect_replacement_bodge.references = @values
|
593
594
|
|
@@ -602,6 +603,7 @@ class ExcelToX
|
|
602
603
|
table_reference_replacer.referring_cell = ref.last
|
603
604
|
table_reference_replacer.map(details.last)
|
604
605
|
@replace_ranges_with_array_literals_replacer.map(details.last)
|
606
|
+
transpose_function_replacer.map(details.last)
|
605
607
|
simplify_arithmetic_replacer.map(details.last)
|
606
608
|
expand_array_formulae_replacer.map(details.last)
|
607
609
|
end
|
data/src/simplify.rb
CHANGED
@@ -20,3 +20,4 @@ require_relative "simplify/replace_arithmetic_on_ranges"
|
|
20
20
|
require_relative "simplify/wrap_formulae_that_return_arrays_and_are_not_in_arrays"
|
21
21
|
require_relative "simplify/replace_string_join_on_ranges"
|
22
22
|
require_relative "simplify/emergency_array_formula_replace_indirect_bodge.rb"
|
23
|
+
require_relative "simplify/replace_transpose_function"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ReplaceTransposeFunction
|
2
|
+
|
3
|
+
def replace(ast)
|
4
|
+
map(ast)
|
5
|
+
end
|
6
|
+
|
7
|
+
def map(ast)
|
8
|
+
return ast unless ast.is_a?(Array)
|
9
|
+
function(ast) if ast[0] == :function
|
10
|
+
ast.each { |a| map(a) }
|
11
|
+
ast
|
12
|
+
end
|
13
|
+
|
14
|
+
def function(ast)
|
15
|
+
return unless ast[1] == :TRANSPOSE
|
16
|
+
array = array_ast_to_ruby_array(ast[2])
|
17
|
+
array = array.transpose
|
18
|
+
ast.replace(ruby_array_to_array_ast(array))
|
19
|
+
ast
|
20
|
+
end
|
21
|
+
|
22
|
+
def array_ast_to_ruby_array(array_ast)
|
23
|
+
return [[array_ast]] unless array_ast.first == :array
|
24
|
+
array_ast[1..-1].map do |row_ast|
|
25
|
+
row_ast[1..-1].map do |cell|
|
26
|
+
cell
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def ruby_array_to_array_ast(ruby_array)
|
32
|
+
[:array].concat(ruby_array.map { |row| [:row].concat(row) })
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- src/simplify/replace_shared_strings.rb
|
245
245
|
- src/simplify/replace_string_join_on_ranges.rb
|
246
246
|
- src/simplify/replace_table_references.rb
|
247
|
+
- src/simplify/replace_transpose_function.rb
|
247
248
|
- src/simplify/replace_values_with_constants.rb
|
248
249
|
- src/simplify/simplify_arithmetic.rb
|
249
250
|
- src/simplify/sort_into_calculation_order.rb
|