Class: Minesweeper::Console::PrettyPrinter::RowPrinter
- Inherits:
-
Object
- Object
- Minesweeper::Console::PrettyPrinter::RowPrinter
- Defined in:
- lib/minesweeper/console/prettyprinter/row_printer.rb
Instance Method Summary collapse
- #build_row_header(row_number, desired_length) ⇒ Object
-
#initialize(separator, theme) ⇒ RowPrinter
constructor
A new instance of RowPrinter.
- #left_padding_for(string, desired_length) ⇒ Object
- #print(row_number, raw_row, column_width) ⇒ Object
Constructor Details
#initialize(separator, theme) ⇒ RowPrinter
Returns a new instance of RowPrinter.
5 6 7 8 9 |
# File 'lib/minesweeper/console/prettyprinter/row_printer.rb', line 5 def initialize(separator, theme) raise ArgumentError if separator.nil? || theme.nil? @separator = separator @theme = theme end |
Instance Method Details
#build_row_header(row_number, desired_length) ⇒ Object
28 29 30 31 32 |
# File 'lib/minesweeper/console/prettyprinter/row_printer.rb', line 28 def build_row_header(row_number, desired_length) result = left_padding_for(row_number.to_s, desired_length) result << @theme.colorize_header(row_number.to_s) result << @theme.colorize_separator(@separator) end |
#left_padding_for(string, desired_length) ⇒ Object
34 35 36 |
# File 'lib/minesweeper/console/prettyprinter/row_printer.rb', line 34 def left_padding_for(string, desired_length) ' ' * (desired_length - string.length) end |
#print(row_number, raw_row, column_width) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/minesweeper/console/prettyprinter/row_printer.rb', line 11 def print(row_number, raw_row, column_width) raise ArgumentError if column_width.nil? raise ArgumentError if column_width < 1 raise ArgumentError if column_width < row_number.to_s.length result = build_row_header(row_number, column_width) raw_row.each_char do |c| result << left_padding_for(c, column_width) if (c =~ /\d+/) result << @theme.colorize_mine_quantity(c) else result << @theme.colorize_cell_status(c) end result << @theme.colorize_separator(@separator) end result end |