class MergeExcel::Settings::ExtraColumn

Constants

DEFAULT_EXTRA_COLUMN_CONFIG

Attributes

data[R]
position[R]

Public Class Methods

new(hash) click to toggle source
# File lib/merge_excel/settings/extra_column.rb, line 29
def initialize(hash)
  # hash: {:position=>:beginning, :data=>[{:type=>:filename, :heading_text=>"Filename"}]}
  @position = hash.fetch(:position){ :beginning }
  @data = []
  read_data_array hash.fetch(:data){ [] }
  validate_position
end
with_defaults() click to toggle source
# File lib/merge_excel/settings/extra_column.rb, line 48
def self.with_defaults
  new(DEFAULT_EXTRA_COLUMN_CONFIG)
end

Public Instance Methods

read_data_array(array) click to toggle source
# File lib/merge_excel/settings/extra_column.rb, line 37
def read_data_array(array)
  array.each do |h|
    if h[:type]==:filename
      @data << FilenameExtraColumn.new(h.fetch(:label){"Filename"})
    elsif h[:type]==:cell_value
      @data << CellValueExtraColumn.new(h.fetch(:label){"Field"}, h)
    end
  end
end

Private Instance Methods

validate_position() click to toggle source
# File lib/merge_excel/settings/extra_column.rb, line 53
def validate_position
  raise "Problem with 'extra_column' settings: 'position' must be :beginning or :end" unless [:beginning, :end].include?(@position)
end