Class: TableData::CoercingRow

Inherits:
Row
  • Object
show all
Defined in:
lib/tabledata/coercing_row.rb

Instance Attribute Summary

Attributes inherited from Row

#data, #index, #table

Instance Method Summary collapse

Methods inherited from Row

#[], #at, #at_accessor, #at_header, #at_index, #each, #inspect, #method_missing, #respond_to_missing?, #size, #slice, #to_hash, #values_at

Constructor Details

#initialize(table, index, data, coercions) ⇒ CoercingRow

Returns a new instance of CoercingRow.



5
6
7
8
# File 'lib/tabledata/coercing_row.rb', line 5

def initialize(table, index, data, coercions)
  @coercions  = coercions
  super(table, index, data.map.with_index { |value, col| coerce(col, value) })
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TableData::Row

Instance Method Details

#coerce(column, value) ⇒ Object



10
11
12
13
# File 'lib/tabledata/coercing_row.rb', line 10

def coerce(column, value)
  coercer = @coercions[column]
  coercer ? coercer.call(value) : value
end