class RassKey::Line

Attributes

default_glyph[RW]
default_length[RW]
default_orientation[RW]
default_padding[RW]
glyph[RW]
line_length[RW]
orientation[RW]
padding[RW]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/rasskey/line.rb, line 20
def initialize(options = {})
  options = {
    :line_length => RassKey::Line.default_length,
    :padding => RassKey::Line.default_padding,
    :glyph => RassKey::Line.default_glyph,
    :orientation => RassKey::Line.default_orientation
  }.merge(options)

  self.line_length = options[:line_length]
  self.padding = options[:padding]
  self.glyph = options[:glyph]
  self.orientation = options[:orientation]

  super()
end

Public Instance Methods

draw(data) click to toggle source
# File lib/rasskey/line.rb, line 36
def draw(data)
  @glyph.length == 1 ? (@glyph = @glyph) : (@glyph = @glyph[0,1])
  spacing = " " * @padding || " "
  line_text = "#{spacing}#{data}#{spacing}"
  begin
    content_line = "#{@glyph * ((@line_length - line_text.length)/2)}#{line_text}#{@glyph * ((@line_length - line_text.length)/2)}"
  rescue
    puts "line length must be larger to accomodate text"
  end
  case @orientation
    when "horizontal"
      content_line
    when "vertical"
      self.vertical(content_line)
    else
      puts "unknown orientation. Should be vertical or horizontal"
  end
end
vertical(data) click to toggle source
# File lib/rasskey/line.rb, line 55
def vertical(data)
  data.split(//).join("\n")
end