class Hellgrid::Views::Console
Attributes
matrix[R]
Public Class Methods
new(matrix)
click to toggle source
# File lib/hellgrid/views/console.rb, line 6 def initialize(matrix) @matrix = matrix end
Public Instance Methods
render()
click to toggle source
# File lib/hellgrid/views/console.rb, line 10 def render puts render_as_string end
render_as_string()
click to toggle source
# 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
Private Instance Methods
column_widths()
click to toggle source
# File lib/hellgrid/views/console.rb, line 33 def column_widths widths = Array.new(matrix[0].size, 0) matrix.each do |row| row.each_with_index do |value, col_i| if value && (widths[col_i] < value.size) widths[col_i] = value.size end end end widths.map { |width| width + 2 } end
row_as_string(row)
click to toggle source
# File lib/hellgrid/views/console.rb, line 29 def row_as_string(row) column_widths.map.with_index { |width, i| (row[i] || 'x').center(width) }.join('|') end