class AsciiParadise::AsciiTable::Row

Public Class Methods

new(table, array = []) click to toggle source
#

initialize

Initialize with width and options.

#
# File lib/ascii_paradise/asciitable/row.rb, line 22
def initialize(table, array = [])
  reset
  @table = table
  array.each { |item| self << item }
end

Public Instance Methods

<<(i)
Alias for: add_cell
[](i) click to toggle source
#

[]

#
# File lib/ascii_paradise/asciitable/row.rb, line 100
def [](i)
  cells[i]
end
add_cell(i) click to toggle source
#

add_cell

#
# File lib/ascii_paradise/asciitable/row.rb, line 46
def add_cell(i)
  options = i.is_a?(Hash) ? i : {:value => i}
  cell = Cell.new(options.merge(:index => @cell_index, :table => @table))
  # ======================================================================= #
  # The next variables are Integers.
  # ======================================================================= #
  @cell_index += cell.colspan # Count up the cell index here.
  @cells << cell
end
Also aliased as: <<
cells()
Alias for: cells?
cells?() click to toggle source
#

cells?

#
# File lib/ascii_paradise/asciitable/row.rb, line 66
def cells?
  @cells
end
Also aliased as: cells
height() click to toggle source
#

height

#
# File lib/ascii_paradise/asciitable/row.rb, line 59
def height
  cells.map { |c| c.lines.count }.max
end
Also aliased as: height?
height?()
Alias for: height
render() click to toggle source
#

render

#
# File lib/ascii_paradise/asciitable/row.rb, line 73
def render
  # ======================================================================= #
  # Obtain a pointer towards the horizontal character, which is usually
  # '-'.
  # ======================================================================= #
  horizontal_token = @table.style.border_y
  # ======================================================================= #
  # Next we check whether to colourize this.
  # ======================================================================= #
  if AsciiTable.use_colours?
    horizontal_token = Colours.send(
      AsciiParadise::AsciiTable.use_which_colours?, horizontal_token
    )
  end
  array = (0...height).to_a
  array.map! { |line|
    horizontal_token + cells.map { |cell|
      cell.render(line)
    }.join(horizontal_token) + horizontal_token
  }
  result = array.join("\n")
  return result
end
reset() click to toggle source
#

reset

#
# File lib/ascii_paradise/asciitable/row.rb, line 31
def reset
  @cells = []
  @cell_index = 0
end
table()
Alias for: table?
table?() click to toggle source
#

table?

#
# File lib/ascii_paradise/asciitable/row.rb, line 39
def table?
  @table
end
Also aliased as: table