Class: Minesweeper::Console::PrettyPrinter::HeaderPrinter
- Inherits:
-
Object
- Object
- Minesweeper::Console::PrettyPrinter::HeaderPrinter
- Defined in:
- lib/minesweeper/console/prettyprinter/header_printer.rb
Instance Method Summary collapse
- #compute_column_width_for(number_of_columns) ⇒ Object
-
#initialize(separator, theme) ⇒ HeaderPrinter
constructor
A new instance of HeaderPrinter.
- #print(number_of_columns) ⇒ Object
Constructor Details
#initialize(separator, theme) ⇒ HeaderPrinter
Returns a new instance of HeaderPrinter.
5 6 7 8 9 |
# 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 |
Instance Method Details
#compute_column_width_for(number_of_columns) ⇒ Object
25 26 27 |
# 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) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |