Class: TinyTable::Row
- Inherits:
-
Object
- Object
- TinyTable::Row
- Extended by:
- Forwardable
- Defined in:
- lib/tinytable/row.rb
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #cell_at(idx) ⇒ Object
- #cell_count ⇒ Object
- #each_cell_with_index(&block) ⇒ Object
-
#initialize(cells, alignments = []) ⇒ Row
constructor
A new instance of Row.
Constructor Details
#initialize(cells, alignments = []) ⇒ Row
Returns a new instance of Row.
11 12 13 14 |
# File 'lib/tinytable/row.rb', line 11 def initialize(cells, alignments = []) @cells = cells || [] @alignments = alignments end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
9 10 11 |
# File 'lib/tinytable/row.rb', line 9 def cells @cells end |
Instance Method Details
#==(obj) ⇒ Object
16 17 18 19 |
# File 'lib/tinytable/row.rb', line 16 def ==(obj) return false unless obj.is_a? Row @cells == obj.cells end |
#cell_at(idx) ⇒ Object
31 32 33 34 35 |
# File 'lib/tinytable/row.rb', line 31 def cell_at(idx) text = @cells.fetch(idx, '') alignment = @alignments[idx] || LEFT Cell.new(text, alignment) end |
#cell_count ⇒ Object
21 22 23 |
# File 'lib/tinytable/row.rb', line 21 def cell_count @cells.count end |
#each_cell_with_index(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/tinytable/row.rb', line 25 def each_cell_with_index(&block) @cells.length.times do |idx| block.call(cell_at(idx), idx) end end |