class Minesweeper::Console::PrettyPrinter::MinefieldPrettyPrinter

Public Class Methods

new(a_minefield, a_theme) click to toggle source
# File lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb, line 11
def initialize(a_minefield, a_theme)
  raise ArgumentError if a_minefield.nil?
  @minefield = a_minefield
  @theme = a_theme
  @header_printer = HeaderPrinter.new('|', @theme)
  @row_printer = RowPrinter.new('|', @theme)
end

Public Instance Methods

print() click to toggle source

Private Instance Methods

generate_header(nb_columns) click to toggle source
# File lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb, line 25
def generate_header(nb_columns)
  @header_printer.print(nb_columns) + "\n"
end
generate_rows(cells, nb_columns) click to toggle source
# File lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb, line 29
def generate_rows(cells, nb_columns)
  max_column_width = (nb_columns - 1).to_s.length
  result = ''
  split_string_in_chunks(cells, nb_columns).each_with_index do |row, i|
    result << @row_printer.print(i, row, max_column_width) + "\n"
  end
  result
end
split_string_in_chunks(a_string, chunk_size) click to toggle source
# File lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb, line 38
def split_string_in_chunks(a_string, chunk_size)
  a_string.scan(/.{#{chunk_size}}/)
end