Class: Hellgrid::Views::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/hellgrid/views/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix) ⇒ Console

Returns a new instance of Console.



8
9
10
# File 'lib/hellgrid/views/console.rb', line 8

def initialize(matrix)
  @matrix = matrix
end

Instance Attribute Details

#matrixObject (readonly)

Returns the value of attribute matrix.



6
7
8
# File 'lib/hellgrid/views/console.rb', line 6

def matrix
  @matrix
end

Instance Method Details

#renderObject



12
13
14
# File 'lib/hellgrid/views/console.rb', line 12

def render
  puts render_as_string
end

#render_as_stringObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hellgrid/views/console.rb', line 16

def render_as_string
  string = []

  string << row_as_string(matrix[0])
  string << column_widths.map { |width| '-' * width }.join('+')

  matrix[1..matrix.size].each do |row|
    string << row_as_string(row)
  end

  "#{string.join("\n")}\n"
end