Class: ExcelWalker::Writer::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/excel_walker/writer/hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition) ⇒ Hook

Returns a new instance of Hook.



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



5
6
7
# File 'lib/excel_walker/writer/hook.rb', line 5

def max
  @max
end

#offsetObject (readonly)

Returns the value of attribute offset.



5
6
7
# File 'lib/excel_walker/writer/hook.rb', line 5

def offset
  @offset
end

#styleObject

Returns the value of attribute style.



6
7
8
# File 'lib/excel_walker/writer/hook.rb', line 6

def style
  @style
end

Instance Method Details

#after_column(offset) ⇒ Object



26
27
28
29
# File 'lib/excel_walker/writer/hook.rb', line 26

def after_column(offset)
  @offset = offset
  self
end

#fill(&block) ⇒ Object



31
32
33
# File 'lib/excel_walker/writer/hook.rb', line 31

def fill(&block)
  @filler = block
end

#match?(row_num) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/excel_walker/writer/hook.rb', line 22

def match?(row_num)
  @matcher[row_num]
end

#run(row_num) ⇒ Object



35
36
37
38
39
40
41
# 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