class Rubyxls::Builders::FormulaBuilder
Attributes
cells[R]
Public Class Methods
new(**opts)
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 7 def initialize(**opts) @value = opts.fetch(:value, nil) @style = opts.fetch(:style, [:default]) @width = opts.fetch(:width, nil) @height = opts.fetch(:height, nil) @data_validation = opts.fetch(:data_validation, nil) @merge = opts.fetch(:merge, nil) @fill = opts.fetch(:fill, :right) @num_cells = opts.fetch(:num_cells, nil) @row_index = opts.fetch(:row_index, nil) @cells = [] fill_right! if @fill == :right fill_down! if @fill == :down fill_all! if @fill == :all end
Private Instance Methods
add_cell!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 46 def add_cell! @cells << { value: @value.nil? ? nil : @value.clone, style: @style, width: @width, height: @height, data_validation: @data_validation, merge: @merge } end
fill_all!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 40 def fill_all! raise "Both num cells & row index cannot be nil when filling all for formula: #{@value}!" if @num_cells.nil? || @row_index.nil? shift_value_down! fill_right! end
fill_down!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 34 def fill_down! raise "Row index cannot be nil when filling down for formula: #{@value}!" if @row_index.nil? shift_value_down! add_cell! end
fill_right!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 26 def fill_right! raise "Num cells cannot be nil when filling right for formula: #{@value}!" if @num_cells.nil? @num_cells.times do add_cell! shift_value_right! end end
shift_value_down!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 54 def shift_value_down! @value.nil? ? nil : @value.gsub!(/(?<=[A-Z])[0-9]+/) { |row| row.to_i + @row_index } end
shift_value_right!()
click to toggle source
# File lib/rubyxls/builders/formula_builder.rb, line 50 def shift_value_right! @value.nil? ? nil : @value.gsub!(/(?<![\$A-Z])[A-Z]+(?=[\$\d])/) { |column| column.next } end