Class: TinyTable::Row

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tinytable/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cellsObject (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_countObject



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