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



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

def initialize(matrix)
  @matrix = matrix
end

Instance Attribute Details

#matrixObject (readonly)

Returns the value of attribute matrix.



4
5
6
# File 'lib/hellgrid/views/console.rb', line 4

def matrix
  @matrix
end

Instance Method Details

#renderObject



10
11
12
# File 'lib/hellgrid/views/console.rb', line 10

def render
  puts render_as_string
end

#render_as_stringObject



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

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