Class: Text::Figlet::Smusher
- Inherits:
-
Object
- Object
- Text::Figlet::Smusher
- Defined in:
- lib/text/figlet/smusher.rb
Instance Method Summary collapse
- #[](result) ⇒ Object
- #callback(s, a, b) ⇒ Object
-
#initialize(font) ⇒ Smusher
constructor
A new instance of Smusher.
- #old_layout?(n) ⇒ Boolean
- #pattern ⇒ Object
- #symbols ⇒ Object
Constructor Details
#initialize(font) ⇒ Smusher
Returns a new instance of Smusher.
6 7 8 9 |
# File 'lib/text/figlet/smusher.rb', line 6 def initialize(font) Text.raise_19_incompat @font = font end |
Instance Method Details
#[](result) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/text/figlet/smusher.rb', line 11 def [](result) todo = false @font.height.times do |j| result[j] = result[j].sub(pattern) { todo, x = callback(todo, $1, $2); x } end @font.height.times do |j| result[j] = if todo result[j].sub(/\s\x00(?!$)|\x00\s/, '').sub(/\x00(?!$)/, '') else result[j].sub(/\x00(?!$)/, '') end end end |
#callback(s, a, b) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/text/figlet/smusher.rb', line 42 def callback(s, a, b) combined = a + b if old_layout?(1) && a == b return true, a elsif old_layout?(2) && ('_' == a && symbols[24].include?(b) || '_' == b && symbols[24].include?(a)) return true, a elsif old_layout?(4) && ((left = symbols[24].index(a)) && (right = symbols[24].index(b))) return true, (right > left ? b : a) elsif old_layout?(8) && (symbols[8].has_key?(b) && symbols[8][b] == a) return true, '|' elsif old_layout?(16) && symbols[16].has_key?(combined) return true, symbols[16][combined] elsif old_layout?(32) && (a == b && @font.hard_blank == a) return true, @font.hard_blank else return s, "#{a}\00#{b}" end end |
#old_layout?(n) ⇒ Boolean
38 39 40 |
# File 'lib/text/figlet/smusher.rb', line 38 def old_layout?(n) @font.old_layout & n > 0 end |
#pattern ⇒ Object
26 27 28 |
# File 'lib/text/figlet/smusher.rb', line 26 def pattern @pattern ||= /([^#{@font.hard_blank}\x00\s])\x00([^#{@font.hard_blank}\x00\s])/ end |
#symbols ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/text/figlet/smusher.rb', line 30 def symbols @@symbols ||= { 24 => '|/\\[]{}()<>', 8 => {'[' => ']', ']' => '[', '{' => '}', '}' => '{', '(' => ')', ')' => '('}, 16 => {"/\\" => '|', "\\/" => 'Y', '><' => 'X'} } end |