Class: RubyFiglet::Figlet
- Inherits:
-
Object
- Object
- RubyFiglet::Figlet
- Defined in:
- lib/ruby_figlet/interface.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.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_figlet/interface.rb', line 18 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruby_figlet/interface.rb', line 64 def self.available folder="#{WD}/fonts/" dir = Dir.entries(folder) (0..dir.size - 1).each do |i| dir[i] += '/' unless dir[i].include? '.' end (0..dir.size - 1).each do |i| dir[i] = "" unless dir[i].include?('.flf') || dir[i].include?('/') 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 list.squeeze! "\n" list.sort_by! &:downcase end |
Instance Method Details
#show ⇒ Object
59 60 61 |
# File 'lib/ruby_figlet/interface.rb', line 59 def show puts stringify end |
#stringify ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_figlet/interface.rb', line 29 def stringify breaks = @string.split "\n" breaks.each_with_index do |break_line, i| string = String.new @height.times do |row| break_line.each { |char| string << @lookup[char][row] } 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 { |line, j| lines[j].insert 0, " " } end string = lines.join "\n" end breaks[i] = string end string = breaks.join "" lines = string.split "\n" offset = 0 (lines.size).times do |j| if lines[j - offset].strip.empty? # when a line is deleted, there must be an offset as the new array is now shorter (after a delete) so we must climb back up it, so that whe don't dlete wrong lines and try to access non-existent indices lines.delete_at(j - offset) # Remove any empty lines offset += 1 end end return lines.join "\n" end |