Class: Text::Figlet::Typesetter
- Inherits:
-
Object
- Object
- Text::Figlet::Typesetter
- Defined in:
- lib/text/figlet/typesetter.rb
Instance Method Summary collapse
- #[](str) ⇒ Object
-
#initialize(font, options = nil) ⇒ Typesetter
constructor
A new instance of Typesetter.
Constructor Details
#initialize(font, options = nil) ⇒ Typesetter
Returns a new instance of Typesetter.
6 7 8 9 10 11 |
# File 'lib/text/figlet/typesetter.rb', line 6 def initialize(font, = nil) Text.raise_19_incompat @font = font @options = || {} @smush = @options.has_key?(:smush) ? @options[:smush] : true end |
Instance Method Details
#[](str) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/text/figlet/typesetter.rb', line 13 def [](str) result = [] str.length.times do |i| char = str[i] unless @font.has_char?(char) if @font.has_char?(0) char = 0 else next end end @font.height.times do |j| line = @font[char][j] if result[j].nil? result[j] = line else result[j] = @font.right_to_left?? (line + result[j]) : (result[j] + line) end end if @font.old_layout > -1 && i > 0 diff = -1 @font.height.times do |j| if match = /\S(\s*\x00\s*)\S/.match(result[j]) len = match[1].length diff = (diff == -1 ? len : min(diff, len)) end end diff -= 1 if diff > 0 @font.height.times do |j| if match = /\x00(\s{0,#{diff}})/.match(result[j]) b = diff - match[1].length result[j] = result[j].sub(/\s{0,#{b}}\x00\s{#{match[1].length}}/, "\0") end end end smush[result] if @smush end end return result.join("\n").gsub(/\0/, '').gsub(@font.hard_blank, ' ') end |