class RubyFiglet::Figlet
Constants
- WD
Public Class Methods
available(folder="
click to toggle source
# File lib/ruby_figlet/interface.rb, line 69 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 dir.sort_by!(&:downcase) 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" end
new(string, font='standard')
click to toggle source
# File lib/ruby_figlet/interface.rb, line 18 def initialize string, font='standard' parsed = Parser.new(font) font_data = parsed.font_table @lookup = font_data[:letter_lookup] @height = font_data[:height] @direction = font_data[:direction] @smushing = font_data[:old_layout] string = string.reverse if @direction == 1 @string = string @font = font end
Public Instance Methods
show()
click to toggle source
# File lib/ruby_figlet/interface.rb, line 64 def show puts stringify end
to_s()
click to toggle source
# File lib/ruby_figlet/interface.rb, line 30 def to_s 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.max_by(&:length).length).each do # Holy Moly, from 0 to (terminal width minus 1) minus max length # of the ASCII art word. lines.each_with_index { |_, 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? lines.delete_at(j - offset) # Remove any empty lines offset += 1 end end lines.join "\n" end
Also aliased as: stringify