Class: RubyFiglet::Figlet
- Inherits:
-
Object
- Object
- RubyFiglet::Figlet
- Defined in:
- lib/ruby_figlet.rb
Constant Summary collapse
- WD =
File.dirname(__FILE__)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string, font = 'standard') ⇒ Figlet
constructor
A new instance of Figlet.
- #show ⇒ Object
- #stringify ⇒ Object
Constructor Details
#initialize(string, font = 'standard') ⇒ Figlet
Returns a new instance of Figlet.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_figlet.rb', line 20 def initialize string, font='standard' data = FigFont::Figlet.new(font).font_data @lookup = data[:lookup_table] @height = data[:height] @direction = data[:direction] @smushing = data[:old_layout] string = string.reverse if @direction == 1 @string = string @font = font end |
Class Method Details
.available(folder = "#{WD}/fonts/") ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_figlet.rb', line 56 def self.available folder="#{WD}/fonts/" dir = Dir.entries(folder) (0..dir.size - 1).each do |i| dir[i] += '/' unless dir[i].include? '.flf' end list = dir.join "\n" ignore = ["..", ".", ".DS_Store", "._.DS_Store", ".DS_Store?", ".Spotlight-V100", ".Trashes", "ehthumbs.db", "Thumbs.db", "desktop.ini"] ignore.each { |file| list.gsub! "#{file}/", "" } list.gsub! ".flf", "" # don't show extensions return list.squeeze "\n" end |
Instance Method Details
#show ⇒ Object
51 52 53 |
# File 'lib/ruby_figlet.rb', line 51 def show print stringify end |
#stringify ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_figlet.rb', line 31 def stringify string = String.new (0..@height - 1).each do |row| @string.each do |char| string << @lookup[char][row] end string << "\n" end if @direction == 1 lines = string.split "\n" (0..(%x[tput cols].to_i - 1) - lines[0].length).each do # Holy Moly, from 0 to (terminal width minus 1) minus length of the ascii art word. lines.each_with_index do |line, i| lines[i].insert 0, " " end end string = lines.join "\n" end return string end |