Class: RubyFromExcel::ArrayFormulaBuilder

Inherits:
FormulaBuilder show all
Defined in:
lib/cells/array/array_formula_builder.rb

Direct Known Subclasses

SingleCellArrayFormulaBuilder

Constant Summary

Constants inherited from FormulaBuilder

FormulaBuilder::COMPARATOR_CONVERSIONS, FormulaBuilder::OPERATOR_CONVERSIONS

Instance Attribute Summary

Attributes inherited from FormulaBuilder

#formula_cell

Instance Method Summary collapse

Methods inherited from FormulaBuilder

#area, #attempt_to_calculate_index, #attempt_to_calculate_match, #attempt_to_parse_indirect, #boolean_false, #boolean_true, #brackets, #cell, #column_range, #comparator, excel_function, #external_reference, #formula, #function, #indirect_function, #initialize, #local_table_reference, #named_reference, #null, #number, #operator, #parse_and_visit, #percentage, #prefix, #range_for, #row_range, #sheet_reference, #single_value_for, #string, #string_join, #table_reference

Constructor Details

This class inherits a constructor from RubyFromExcel::FormulaBuilder

Instance Method Details

#arithmetic(*strings) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cells/array/array_formula_builder.rb', line 43

def arithmetic(*strings)
  matrix_strings = []
  matrix_string_references = []
  strings = strings.map do |s|
    if s.type == :operator
      s.visit(self)
    else
      matrix_strings << s.visit(self)
      matrix_string_references << "r#{matrix_string_references.size+1}"
      matrix_string_references.last
    end
  end
  "m(#{matrix_strings.join(',')}) { |#{matrix_string_references.join(',')}| #{strings.join} }"
end

#comparison(left, comparison, right) ⇒ Object



39
40
41
# File 'lib/cells/array/array_formula_builder.rb', line 39

def comparison(left,comparison,right)
  "m(#{left.visit(self)},#{right.visit(self)}) { |r1,r2| r1#{comparison.visit(self)}r2 }"
end

#index_function(index_range, *args) ⇒ Object



26
27
28
29
# File 'lib/cells/array/array_formula_builder.rb', line 26

def index_function(index_range,*args)
  arg_names = (1..(args.size)).map { |i| "r#{i}" }
  "m(#{args.map {|a| a.visit(self) }.join(',')}) { |#{arg_names.join(',')}| index(#{index_range.visit(self)},#{arg_names.join(',')}) }"
end

#match_function(lookup_value, lookup_array, match_type = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/cells/array/array_formula_builder.rb', line 31

def match_function(lookup_value,lookup_array,match_type = nil)
  if match_type
    "m(#{lookup_value.visit(self)},#{match_type.visit(self)}) { |r1,r2| match(r1,#{lookup_array.visit(self)},r2) }"
  else
    "m(#{lookup_value.visit(self)}) { |r1| match(r1,#{lookup_array.visit(self)}) }"
  end
end

#standard_function(name_to_use_in_ruby, args) ⇒ Object



21
22
23
24
# File 'lib/cells/array/array_formula_builder.rb', line 21

def standard_function(name_to_use_in_ruby,args)
  arg_names = (1..(args.size)).map { |i| "r#{i}" }
  "m(#{args.map {|a| a.visit(self) }.join(',')}) { |#{arg_names.join(',')}| #{name_to_use_in_ruby}(#{arg_names.join(',')}) }"
end

#sum_function(*args) ⇒ Object



4
5
6
# File 'lib/cells/array/array_formula_builder.rb', line 4

def sum_function(*args)
  "sum(#{args.map {|a| a.visit(self)}.join(',')})"
end

#sumif_function(check_range, criteria, sum_range = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/cells/array/array_formula_builder.rb', line 8

def sumif_function(check_range,criteria,sum_range = nil)
  if sum_range
    "m(#{criteria.visit(self)}) { |r1| sumif(#{check_range.visit(self)},r1,#{sum_range.visit(self)}) }"
  else
    "m(#{criteria.visit(self)}) { |r1| sumif(#{check_range.visit(self)},r1) }"
  end
end

#sumifs_function(sum_range, *args) ⇒ Object



16
17
18
19
# File 'lib/cells/array/array_formula_builder.rb', line 16

def sumifs_function(sum_range,*args)
  checks = Hash[*args]
  "m(#{checks.values.map {|a| a.visit(self) }.join(',')}) { |#{checks.values.map.with_index {|a,i| "r#{i+1}"}.join(',')}| sumifs(#{sum_range.visit(self)},#{checks.map.with_index { |a,i| "#{a.first.visit(self)},r#{i+1}" }.join(',')}) }"
end