Class: Megingiard::CenteredCanvas

Inherits:
Object
  • Object
show all
Defined in:
lib/megingiard/centered_canvas.rb

Overview

An area that can be drawn on, everything is centered

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ CenteredCanvas

Returns a new instance of CenteredCanvas.



9
10
11
12
# File 'lib/megingiard/centered_canvas.rb', line 9

def initialize(output)
  @output = output
  @left_column_drawn = false
end

Instance Method Details

#draw_centered_row(node) ⇒ Object

A full-width row where the content is centered



33
34
35
36
# File 'lib/megingiard/centered_canvas.rb', line 33

def draw_centered_row(node)
  node = CenteredNode.new(TERMINAL_WIDTH, node)
  end_line_with(node)
end

#draw_left_column(node) ⇒ Object

The left half of a full-width row with right aligned content



20
21
22
23
24
# File 'lib/megingiard/centered_canvas.rb', line 20

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) ⇒ Object

The right half of a full-width row



27
28
29
30
# File 'lib/megingiard/centered_canvas.rb', line 27

def draw_right_column(node)
  node = Node.new(EMPTY_CELL, node) unless left_column_drawn?
  end_line_with(node)
end

#left_column_drawn?Boolean

Check if a left column has been drawn

Returns:

  • (Boolean)


15
16
17
# File 'lib/megingiard/centered_canvas.rb', line 15

def left_column_drawn?
  @left_column_drawn
end