Class: AsciiParadise::AsciiTable::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/ascii_paradise/asciitable/row.rb

Direct Known Subclasses

Separator

Instance Method Summary collapse

Constructor Details

#initialize(table, array = []) ⇒ Row

#

initialize

Initialize with width and options.

#


22
23
24
25
26
# File 'lib/ascii_paradise/asciitable/row.rb', line 22

def initialize(table, array = [])
  reset
  @table = table
  array.each { |item| self << item }
end

Instance Method Details

#[](i) ⇒ Object

#

[]

#


100
101
102
# File 'lib/ascii_paradise/asciitable/row.rb', line 100

def [](i)
  cells[i]
end

#add_cell(i) ⇒ Object Also known as: <<

#

add_cell

#


46
47
48
49
50
51
52
53
54
# 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

#cells?Boolean Also known as: cells

#

cells?

#

Returns:

  • (Boolean)


66
67
68
# File 'lib/ascii_paradise/asciitable/row.rb', line 66

def cells?
  @cells
end

#heightObject Also known as: height?

#

height

#


59
60
61
# File 'lib/ascii_paradise/asciitable/row.rb', line 59

def height
  cells.map { |c| c.lines.count }.max
end

#renderObject

#

render

#


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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

#resetObject

#

reset

#


31
32
33
34
# File 'lib/ascii_paradise/asciitable/row.rb', line 31

def reset
  @cells = []
  @cell_index = 0
end

#table?Boolean Also known as: table

#

table?

#

Returns:

  • (Boolean)


39
40
41
# File 'lib/ascii_paradise/asciitable/row.rb', line 39

def table?
  @table
end