Class: Turntable::Table
- Inherits:
-
Object
- Object
- Turntable::Table
- Includes:
- Enumerable
- Defined in:
- lib/turntable/table.rb
Overview
Turntable::Table is Turntable’s main interface. It maintains an ordered list of Turntable::Row objects, according to a given Turntable::TableHeader.
Internally, Turntable::Table implements a SortedSet. See the documentation for Turntable::TableHeader for the reasons why. Additionally, the SortedSet ensures that two otherwise identical rows will have differing positions within the table.
Turntable::Table includes Enumerable, so every method there is available here. Also, calling Turntable::Table#rows returns the internal SortedSet, so you can gain access to the instance methods available for sets that way.
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
-
#[](position) ⇒ Object
Retreives a row by its position.
- #each ⇒ Object
-
#initialize(header) ⇒ Table
constructor
Associates a TableHeader with a new, empty Table.
-
#push(*data) ⇒ Object
Append a new Row to the Table.
Constructor Details
#initialize(header) ⇒ Table
Associates a TableHeader with a new, empty Table.
34 35 36 37 |
# File 'lib/turntable/table.rb', line 34 def initialize(header) @rows = SortedSet.new @header = header end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
29 30 31 |
# File 'lib/turntable/table.rb', line 29 def header @header end |
#rows ⇒ Object
Returns the value of attribute rows.
30 31 32 |
# File 'lib/turntable/table.rb', line 30 def rows @rows end |
Instance Method Details
#[](position) ⇒ Object
Retreives a row by its position.
59 60 61 |
# File 'lib/turntable/table.rb', line 59 def [](position) @rows.detect { |row| row.position == position } end |
#each ⇒ Object
25 26 27 |
# File 'lib/turntable/table.rb', line 25 def each @rows.each { |row| yield row } end |