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.



96
97
98
99
100
# File 'lib/exwiw/row_transformer.rb', line 96

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.



102
103
104
# File 'lib/exwiw/row_transformer.rb', line 102

def values=(value)
  @values = value
end

Instance Method Details

#[](column_name) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/exwiw/row_transformer.rb', line 104

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