Class: Exwiw::RowTransformer::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/exwiw/row_transformer.rb

Overview

The r a map proc receives: read-only access to the current row's values by column name (r['id']). One instance is reused across all rows (zero per-row allocation) — do not retain it outside the proc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, name_to_index) ⇒ Row

Returns a new instance of Row.



57
58
59
60
61
# File 'lib/exwiw/row_transformer.rb', line 57

def initialize(table_name, name_to_index)
  @table_name = table_name
  @name_to_index = name_to_index
  @values = nil
end

Instance Attribute Details

#values=(value) ⇒ Object (writeonly)

Sets the attribute values

Parameters:

  • value

    the value to set the attribute values to.



63
64
65
# File 'lib/exwiw/row_transformer.rb', line 63

def values=(value)
  @values = value
end

Instance Method Details

#[](column_name) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/exwiw/row_transformer.rb', line 65

def [](column_name)
  index = @name_to_index[column_name]
  unless index
    raise ArgumentError,
          "unknown column '#{column_name}' in map proc for table '#{@table_name}' " \
          "(available: #{@name_to_index.keys.join(', ')})"
  end
  @values[index]
end