class Llamascii::Drawer

Constants

MAX_LINE_LENGTH

Attributes

message[R]

Public Class Methods

draw(message) click to toggle source
# File lib/llamascii/drawer.rb, line 14
def self.draw(message)
  d = Drawer.new(message)
  output = ""
  output << d.draw_llama
  output << d.draw_message
end
new(message = "") click to toggle source
# File lib/llamascii/drawer.rb, line 10
def initialize(message = "")
  @message = message
end

Public Instance Methods

draw_llama() click to toggle source
# File lib/llamascii/drawer.rb, line 21
def draw_llama
  base_llama
end
draw_message() click to toggle source
# File lib/llamascii/drawer.rb, line 25
def draw_message
  return "" if message.nil? || message.empty?

  "".tap do |o|
    #o << "-".center(MAX_LINE_LENGTH+5, '-')
    #o << "\n"
    o << formatted_message
    #o << "\n"
    #o << "-".center(MAX_LINE_LENGTH+5, '-')
    #o << "\n"
  end
end

Protected Instance Methods

base_llama() click to toggle source
# File lib/llamascii/drawer.rb, line 51
    def base_llama
      <<-LLAMA
       ,
      ~)
       (_---;
        /|~|\\
       / / /|
      LLAMA
    end
formatted_message() click to toggle source
# File lib/llamascii/drawer.rb, line 40
def formatted_message
  msg = message.gsub("\n", "").gsub("\r", "")
  # split after x words, when x+1 words is > MAX_LINE_LENGTH
  msg = word_wrap(msg, line_width: MAX_LINE_LENGTH + 5)
  centered = ""
  msg.split("\n").each do |line|
    centered << '|' << line.center(MAX_LINE_LENGTH + 5, ' ') << "|\n"
  end.join("")
  centered
end