Class: Artii::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/artii/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#facesObject

Returns the value of attribute faces.



9
10
11
# File 'lib/artii/base.rb', line 9

def faces
  @faces
end

#fontObject

Returns the value of attribute font.



9
10
11
# File 'lib/artii/base.rb', line 9

def font
  @font
end

Instance Method Details

#all_fontsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object Also known as: output



34
35
36
37
# File 'lib/artii/base.rb', line 34

def asciify(string)
  figlet = Artii::Figlet::Typesetter.new(@font)
  figlet[string]
end

#font_file(name) ⇒ Object



30
31
32
# File 'lib/artii/base.rb', line 30

def font_file(name)
  "#{FONTPATH}/#{@faces[name]}"
end

#font_nameObject



26
27
28
# File 'lib/artii/base.rb', line 26

def font_name
  @faces[@options[:font]]
end

#list_all_fontsObject



40
41
42
43
44
45
46
# 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

#versionObject



73
74
75
76
77
78
79
# 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