class Squarify::Console

This module contains the Squarify classes

Attributes

record[R]

This class allows formatting text like a ticket

size[R]

This class allows formatting text like a ticket

stdout[R]

This class allows formatting text like a ticket

Public Class Methods

new(size, record: false) click to toggle source
# File lib/squarify.rb, line 11
def initialize(size, record: false)
  @size = size
  @record = record
  @stdout = "" if record
end

Public Instance Methods

line(options: nil) click to toggle source
# File lib/squarify.rb, line 17
def line(options: nil)
  box "━" * (@size - 2), options
end
text(sentence, options = nil) click to toggle source
# File lib/squarify.rb, line 21
def text(sentence, options = nil)
  if options.eql? "center"
    sentence = truncate(sentence.center(@size - 2), @size - 2)
  else
    sentence = truncate(sentence, @size - 2)
    sentence += " " * (@size - sentence.length - 2)
  end
  @stdout += "#{sentence}\n" if @record
  box sentence, options
end

Private Instance Methods

box(sentence, options) click to toggle source
# File lib/squarify.rb, line 34
def box(sentence, options)
  case options
  when "top"
    "┏#{sentence}┓"
  when "bottom"
    "┗#{sentence}┛"
  when "middle"
    "┣#{sentence}┫"
  else
    "┃#{sentence}┃"
  end
end
truncate(string, max) click to toggle source
# File lib/squarify.rb, line 47
def truncate(string, max)
  string.length > max ? "#{string[0...max - 3]}..." : string
end