Sha256: 49523ace207e6e913bbc60529d9e1dab2da6821807e62d24e394b588db622367
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
require 'figlet_interpreter' class String def each i = 0 while i < self.length yield self[i] i += 1 end end end module RubyFiglet refine String do def art(font='standard'); RubyFiglet::Figlet.new(self, font).stringify end def art!(font='standard'); replace art(font) end end class Figlet 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 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 def show print stringify end WD = File.dirname(__FILE__) 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby_figlet-0.2.1 | lib/ruby_figlet.rb |
ruby_figlet-0.2.0 | lib/ruby_figlet.rb |