class Minesweeper::Console::PrettyPrinter::HeaderPrinter
Public Class Methods
new(separator, theme)
click to toggle source
# File lib/minesweeper/console/prettyprinter/header_printer.rb, line 5 def initialize(separator, theme) raise ArgumentError if separator.nil? || theme.nil? @separator = separator @theme = theme end
Public Instance Methods
compute_column_width_for(number_of_columns)
click to toggle source
# File lib/minesweeper/console/prettyprinter/header_printer.rb, line 25 def compute_column_width_for(number_of_columns) (number_of_columns - 1).to_s.length end
print(number_of_columns)
click to toggle source
# File lib/minesweeper/console/prettyprinter/header_printer.rb, line 11 def print(number_of_columns) raise ArgumentError if number_of_columns <= 0 column_width = compute_column_width_for(number_of_columns) result = ' ' * column_width result << @theme.colorize_separator(@separator) number_of_columns.times do |i| column_header = @theme.colorize_header(i.to_s) column_header.prepend(' ' * (column_width - i.to_s.length)) result << column_header result << @theme.colorize_separator(@separator) end result end