Class: Turntable::Row

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/turntable/row.rb

Overview

A Turntable::Row represents one row in a Turntable::Table, according to the table’s Turntable::TableHeader.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, position, data_array) ⇒ Row

This method is not meant to be used directly. Refer to Turntable::Table.



27
28
29
30
31
# File 'lib/turntable/row.rb', line 27

def initialize(header, position, data_array)
  @header   = header  # FIXME This makes IRB really ugly
  @position = position
  @data     = data_array
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



23
24
25
# File 'lib/turntable/row.rb', line 23

def data
  @data
end

#positionObject (readonly)

Returns the value of attribute position.



23
24
25
# File 'lib/turntable/row.rb', line 23

def position
  @position
end

Instance Method Details

#<=>(another) ⇒ Object

A Row is “less than” another if its position is smaller. Likewise, a Row is “greater than” another if its position is larger.



19
20
21
# File 'lib/turntable/row.rb', line 19

def <=>(another)
  (self.position > another.position) ? (1) : (-1)
end

#[](column_name) ⇒ Object

Returns the data found at a specific column. TODO @data should have this close by…



36
37
38
39
# File 'lib/turntable/row.rb', line 36

def [](column_name)
  i = @header.detect { |column| column.name == column_name }.position
  @data[i]
end