Class: NicePrinter

Inherits:
Object show all
Defined in:
lib/poolparty/helpers/nice_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_linesObject (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_linesObject

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

#emptyObject



23
24
25
# File 'lib/poolparty/helpers/nice_printer.rb', line 23

def empty
  lines << "* #{" ".ljust(@centered_lines)} *"
end


20
21
22
# File 'lib/poolparty/helpers/nice_printer.rb', line 20

def footer
  header
end

#headerObject



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

#linesObject



33
34
35
# File 'lib/poolparty/helpers/nice_printer.rb', line 33

def lines
  @lines ||= []
end


26
27
28
29
# File 'lib/poolparty/helpers/nice_printer.rb', line 26

def print
  puts lines.join("\n")
  ""
end