class ExcelWalker::Writer::Hook

Attributes

max[R]
offset[R]
style[RW]

Public Class Methods

new(condition) click to toggle source
# File lib/excel_walker/writer/hook.rb, line 8
def initialize(condition)
  @matcher = case true
               when condition.is_a?(Range), condition.is_a?(Array)
                 @max = condition.max
                 proc { |row_num| condition.include?(row_num) }
               when condition.is_a?(Fixnum)
                 @max = condition
                 proc { |row_num| condition === row_num }
               else
                 raise ArgumentError.new('Can only take Range, Integers or Arrays')
             end
  @row_index = 0
end

Public Instance Methods

after_column(offset) click to toggle source
# File lib/excel_walker/writer/hook.rb, line 26
def after_column(offset)
  @offset = offset
  self
end
fill(&block) click to toggle source
# File lib/excel_walker/writer/hook.rb, line 31
def fill(&block)
  @filler = block
end
match?(row_num) click to toggle source
# File lib/excel_walker/writer/hook.rb, line 22
def match?(row_num)
  @matcher[row_num]
end
run(row_num) click to toggle source
# File lib/excel_walker/writer/hook.rb, line 35
def run(row_num)
  cells = Cells.new(style)
  @filler[cells, @row_index, row_num]
  cells.build
  @row_index += 1
  cells
end