class Megingiard::CenteredCanvas
An area that can be drawn on, everything is centered
Public Class Methods
new(output)
click to toggle source
# File lib/megingiard/centered_canvas.rb, line 8 def initialize(output) @output = output @left_column_drawn = false end
Public Instance Methods
draw_centered_row(node)
click to toggle source
A full-width row where the content is centered
# File lib/megingiard/centered_canvas.rb, line 32 def draw_centered_row(node) node = CenteredNode.new(TERMINAL_WIDTH, node) end_line_with(node) end
draw_left_column(node)
click to toggle source
The left half of a full-width row with right aligned content
# File lib/megingiard/centered_canvas.rb, line 19 def draw_left_column(node) right_adjusted_text = node.to_s.rjust(CELL_WIDTH) @output.print right_adjusted_text @left_column_drawn = true end
draw_right_column(node)
click to toggle source
The right half of a full-width row
# File lib/megingiard/centered_canvas.rb, line 26 def draw_right_column(node) node = Node.new(EMPTY_CELL, node) unless left_column_drawn? end_line_with(node) end
left_column_drawn?()
click to toggle source
Check if a left column has been drawn
# File lib/megingiard/centered_canvas.rb, line 14 def left_column_drawn? @left_column_drawn end
Private Instance Methods
end_line_with(element)
click to toggle source
# File lib/megingiard/centered_canvas.rb, line 39 def end_line_with(element) @output.puts(element.to_s) @left_column_drawn = false end