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
- #to_s ⇒ Object (also: #stringify)
Constructor Details
#initialize(string, font = 'standard') ⇒ Figlet
Returns a new instance of Figlet.
18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Class Method Details
.available(folder = "#{WD}/fonts/") ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |
Instance Method Details
#show ⇒ Object
64 65 66 |
# File 'lib/ruby_figlet/interface.rb', line 64 def show puts stringify end |
#to_s ⇒ Object Also known as: stringify
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 58 59 60 |
# 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 |