class Artii::Base

Attributes

faces[RW]
font[RW]

Public Class Methods

new(params={}) click to toggle source
# File lib/artii/base.rb, line 11
def initialize(params={})
  if params.is_a?(String)
    params = {
      :text => params
    }
  end

  @options = {
    :font => "big"
  }.merge(params)

  @faces = all_fonts
  @font = Artii::Figlet::Font.new font_file(@options[:font])
end

Public Instance Methods

all_fonts() click to toggle source
# File lib/artii/base.rb, line 48
def all_fonts
  font_faces = {}
  size_of_fontpath = FONTPATH.split('/').size
  font_exts = %w(flf) # FIXME: was %w(flf flc) but the .flc format seems to not be recognized. Need to investigate further.

  Find.find(FONTPATH) do |file|
    ext = File.extname(file).gsub('.','')
    next if (File.directory?(file) or !font_exts.include?(ext))

    dir = File.dirname(file).split('/')
    if dir.size > size_of_fontpath
      dir = "#{dir.last}/"
    else
      dir = ''
    end

    filename = File.basename(file)
    filename = "#{dir}#{filename}"

    font_faces[File.basename(file, ".#{ext}")] = filename
  end

  font_faces
end
asciify(string) click to toggle source
# File lib/artii/base.rb, line 34
def asciify(string)
  figlet = Artii::Figlet::Typesetter.new(@font)
  figlet[string]
end
Also aliased as: output
font_file(name) click to toggle source
# File lib/artii/base.rb, line 30
def font_file(name)
  "#{FONTPATH}/#{@faces[name]}"
end
font_name() click to toggle source
# File lib/artii/base.rb, line 26
def font_name
  @faces[@options[:font]]
end
list_all_fonts() click to toggle source
# File lib/artii/base.rb, line 40
def list_all_fonts
  font_list = "\n--------------------\nAll Available Fonts:\n--------------------\n\n"
  @faces.sort.each do |k,v|
    font_list += "#{k}\n"
  end
  font_list += "\n--------------------------\nTotal Available Fonts: #{@faces.size}\n\n"
end
output(string)
Alias for: asciify
version() click to toggle source
# File lib/artii/base.rb, line 73
def version
  file = 'artii.gemspec'
  unless File.exists? file
    file = `gem which artii`.sub("/lib/artii.rb\n", "/#{file}")
  end
  Gem::Specification::load(file).version.to_s
end