module Bcome::Draw

Constants

BLIP
BOTTOM_ANCHOR

Tree shapes

BOX_BOTTOM_LEFT
BOX_BOTTOM_RIGHT
BOX_HORIZONTAL_LINE
BOX_SIDE

 Box shapes

BOX_TOP_LEFT
BOX_TOP_RIGHT
BRANCH
INGRESS
LEFT_PADDING
MID_SHIPS

Public Instance Methods

box_it(array_of_lines, padding = 1, _box_colour = :bc_cyan) click to toggle source

Takes an array of strings, each representing a line Draws a box around the lines, and returns a new array padding may be provided

# File lib/objects/modules/draw.rb, line 26
def box_it(array_of_lines, padding = 1, _box_colour = :bc_cyan)
  max_length = max_box_line_length(array_of_lines)
  pad_string = "\s" * padding

  box_lines = [
    # Set the top box line
    "#{BOX_TOP_LEFT}#{BOX_HORIZONTAL_LINE * (max_length + (padding + 1))}#{BOX_TOP_RIGHT}"
  ]

  array_of_lines.each do |line|
    line_length = line.sanitize.length
    box_lines << "#{BOX_SIDE}#{pad_string}" + line.to_s + "#{"\s" * (max_length - line_length)}#{pad_string}#{BOX_SIDE}"
  end

  # Set the bottom box line
  box_lines << "#{BOX_BOTTOM_LEFT}#{BOX_HORIZONTAL_LINE * (max_length + (padding + 1))}#{BOX_BOTTOM_RIGHT}"
  box_lines
end
max_box_line_length(array_of_lines) click to toggle source
# File lib/objects/modules/draw.rb, line 45
def max_box_line_length(array_of_lines)
  array_of_lines.max_by { |string| string.sanitize.length }.sanitize.length
end