Module: Clacky::BlockFont
- Defined in:
- lib/clacky/block_font.rb
Overview
BlockFont renders text using Unicode box-drawing characters (█ ║ ╗ ╔ ╚ ╝ ═) in the same visual style as the hardcoded OpenClacky logo.
Each glyph is 6 lines tall. Characters are joined horizontally with one space column between them.
Constant Summary collapse
- GLYPHS =
Each letter is defined as an array of exactly 6 strings (equal width). rubocop:disable Layout/ExtraSpacing, Layout/SpaceInsideArrayLiteralBrackets
{ "0" => [ " ██████╗ ", "██╔═══██╗", "██║██╗██║", "██║╚█╔╝██║", "╚██████╔╝", " ╚═════╝ ", ], "1" => [ " ██╗", "███║", "╚██║", " ██║", " ██║", " ╚═╝", ], "2" => [ "██████╗ ", "╚════██╗", " █████╔╝", "██╔═══╝ ", "███████╗", "╚══════╝", ], "3" => [ "██████╗ ", "╚════██╗", " █████╔╝", " ╚═══██╗", "██████╔╝", "╚═════╝ ", ], "4" => [ "██╗ ██╗", "██║ ██║", "███████║", "╚════██║", " ██║", " ╚═╝", ], "5" => [ "███████╗", "██╔════╝", "███████╗", "╚════██║", "███████║", "╚══════╝", ], "6" => [ " ██████╗ ", "██╔════╝ ", "███████╗ ", "██╔═══██╗", "╚██████╔╝", " ╚═════╝ ", ], "7" => [ "███████╗", "╚════██║", " ██╔╝", " ██╔╝ ", " ██║ ", " ╚═╝ ", ], "8" => [ " █████╗ ", "██╔══██╗", "╚█████╔╝", "██╔══██╗", "╚█████╔╝", " ╚════╝ ", ], "9" => [ " █████╗ ", "██╔══██╗", "╚██████║", " ╚═══██║", " █████╔╝", " ╚════╝ ", ], " " => [ " ", " ", " ", " ", " ", " ", ], "a" => [ " ████╗ ", "██╔══██╗", "███████║", "██╔══██║", "██║ ██║", "╚═╝ ╚═╝", ], "b" => [ "██████╗ ", "██╔══██╗", "██████╔╝", "██╔══██╗", "██████╔╝", "╚═════╝ ", ], "c" => [ " ██████╗", "██╔════╝", "██║ ", "██║ ", "╚██████╗", " ╚═════╝", ], "d" => [ "██████╗ ", "██╔══██╗", "██║ ██║", "██║ ██║", "██████╔╝", "╚═════╝ ", ], "e" => [ "███████╗", "██╔════╝", "█████╗ ", "██╔══╝ ", "███████╗", "╚══════╝", ], "f" => [ "███████╗", "██╔════╝", "█████╗ ", "██╔══╝ ", "██║ ", "╚═╝ ", ], "g" => [ " ██████╗ ", "██╔════╝ ", "██║ ███╗", "██║ ██║", "╚██████╔╝", " ╚═════╝ ", ], "h" => [ "██╗ ██╗", "██║ ██║", "███████║", "██╔══██║", "██║ ██║", "╚═╝ ╚═╝", ], "i" => [ "██╗", "██║", "██║", "██║", "██║", "╚═╝", ], "j" => [ " ██╗", " ██║", " ██║", " ██║", "███║", "╚══╝", ], "k" => [ "██╗ ██╗", "██║ ██╔╝", "█████╔╝ ", "██╔═██╗ ", "██║ ██╗", "╚═╝ ╚═╝", ], "l" => [ "██╗ ", "██║ ", "██║ ", "██║ ", "███████╗", "╚══════╝", ], "m" => [ "███╗ ███╗", "████╗ ████║", "██╔████╔██║", "██║╚██╔╝██║", "██║ ╚═╝ ██║", "╚═╝ ╚═╝", ], "n" => [ "███╗ ██╗", "████╗ ██║", "██╔██╗ ██║", "██║╚██╗██║", "██║ ╚████║", "╚═╝ ╚═══╝", ], "o" => [ " ██████╗ ", "██╔═══██╗", "██║ ██║", "██║ ██║", "╚██████╔╝", " ╚═════╝ ", ], "p" => [ "██████╗ ", "██╔══██╗", "██████╔╝", "██╔═══╝ ", "██║ ", "╚═╝ ", ], "q" => [ " ██████╗ ", "██╔═══██╗", "██║ ██║", "██║▄▄ ██║", "╚██████╔╝", " ╚══▀▀═╝ ", ], "r" => [ "██████╗ ", "██╔══██╗", "██████╔╝", "██╔══██╗", "██║ ██║", "╚═╝ ╚═╝", ], "s" => [ "███████╗", "██╔════╝", "███████╗", "╚════██║", "███████║", "╚══════╝", ], "t" => [ "████████╗", "╚══██╔══╝", " ██║ ", " ██║ ", " ██║ ", " ╚═╝ ", ], "u" => [ "██╗ ██╗", "██║ ██║", "██║ ██║", "██║ ██║", "╚██████╔╝", " ╚═════╝ ", ], "v" => [ "██╗ ██╗", "██║ ██║", "██║ ██║", "╚██╗ ██╔╝", " ╚████╔╝ ", " ╚═══╝ ", ], "w" => [ "██╗ ██╗", "██║ ██║", "██║ █╗ ██║", "██║███╗██║", "╚███╔███╔╝", " ╚══╝╚══╝ ", ], "x" => [ "██╗ ██╗", "╚██╗██╔╝", " ╚███╔╝ ", " ██╔██╗ ", "██╔╝ ██╗", "╚═╝ ╚═╝", ], "y" => [ "██╗ ██╗", "╚██╗ ██╔╝", " ╚████╔╝ ", " ╚██╔╝ ", " ██║ ", " ╚═╝ ", ], "z" => [ "███████╗", "╚════██║", " ██╔╝", " ██╔╝ ", "███████╗", "╚══════╝", ], }.freeze
- HEIGHT =
rubocop:enable Layout/ExtraSpacing, Layout/SpaceInsideArrayLiteralBrackets
6- GLYPH_GAP =
" "
Class Method Summary collapse
-
.render(text) ⇒ Object
Render a string as block-font art.
-
.width(text) ⇒ Object
Return the pixel width of the rendered text (longest line length).
Class Method Details
.render(text) ⇒ Object
Render a string as block-font art. Unknown characters fall back to space. Returns a multi-line string (6 lines joined by newlines).
317 318 319 320 321 322 323 324 |
# File 'lib/clacky/block_font.rb', line 317 def self.render(text) chars = text.downcase.chars glyphs = chars.map { |c| GLYPHS[c] || GLYPHS[" "] } HEIGHT.times.map do |row| glyphs.map { |g| g[row] }.join(GLYPH_GAP) end.join("\n") end |
.width(text) ⇒ Object
Return the pixel width of the rendered text (longest line length).
327 328 329 |
# File 'lib/clacky/block_font.rb', line 327 def self.width(text) render(text).lines.map { |l| l.chomp.length }.max.to_i end |