Class: NicePrinter
Instance Attribute Summary collapse
-
#centered_lines ⇒ Object
readonly
Returns the value of attribute centered_lines.
-
#num_lines ⇒ Object
Returns the value of attribute num_lines.
Instance Method Summary collapse
- #<<(line) ⇒ Object
- #center(line) ⇒ Object
- #empty ⇒ Object
- #footer ⇒ Object
- #header ⇒ Object
-
#initialize(num_lines = 60) ⇒ NicePrinter
constructor
A new instance of NicePrinter.
- #left(line) ⇒ Object
- #lines ⇒ Object
- #print ⇒ Object
Constructor Details
#initialize(num_lines = 60) ⇒ NicePrinter
Returns a new instance of NicePrinter.
6 7 8 9 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 6 def initialize(num_lines=60) @num_lines = num_lines @centered_lines = @num_lines - 4 end |
Instance Attribute Details
#centered_lines ⇒ Object (readonly)
Returns the value of attribute centered_lines.
4 5 6 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 4 def centered_lines @centered_lines end |
#num_lines ⇒ Object
Returns the value of attribute num_lines.
3 4 5 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 3 def num_lines @num_lines end |
Instance Method Details
#<<(line) ⇒ Object
30 31 32 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 30 def <<(line) left(line) end |
#center(line) ⇒ Object
11 12 13 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 11 def center(line) lines << "* #{line.center(@centered_lines)} *" end |
#empty ⇒ Object
23 24 25 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 23 def empty lines << "* #{" ".ljust(@centered_lines)} *" end |
#footer ⇒ Object
20 21 22 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 20 def header end |
#header ⇒ Object
17 18 19 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 17 def header lines << "*"*@num_lines end |
#left(line) ⇒ Object
14 15 16 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 14 def left(line) lines << "* #{line.ljust(@centered_lines)} *" end |
#lines ⇒ Object
33 34 35 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 33 def lines @lines ||= [] end |
#print ⇒ Object
26 27 28 29 |
# File 'lib/poolparty/helpers/nice_printer.rb', line 26 def print puts lines.join("\n") "" end |