Class: ArrayTransform::Operations::AddIndexColumn

Inherits:
Object
  • Object
show all
Includes:
Callable
Defined in:
lib/array_transform/operations/add_index_column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callable

included

Constructor Details

#initialize(new_column_header: nil, data:, index_offset: 0) ⇒ AddIndexColumn

Returns a new instance of AddIndexColumn.



6
7
8
9
10
11
12
13
14
# File 'lib/array_transform/operations/add_index_column.rb', line 6

def initialize(
  new_column_header: nil,
  data:,
  index_offset: 0
)
  @new_column_header = new_column_header
  @data = data
  @index_offset = index_offset
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/array_transform/operations/add_index_column.rb', line 16

def data
  @data
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
# File 'lib/array_transform/operations/add_index_column.rb', line 18

def call
  AddColumn.call(
    cell_operation: -> (row_index) { row_index + index_offset },
    data: data,
    new_column_header: new_column_header
  )
end