Class: Judges::AsciiLoog
Overview
ASCII wrapper for Loog logging facility.
This class wraps any Loog logger and converts Unicode symbols to ASCII equivalents when the –ascii option is enabled.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2026 Yegor Bugayenko
- License
-
MIT
Constant Summary collapse
- UNICODE_TO_ASCII =
Unicode to ASCII symbol mapping
{ '👍' => '+', '👎' => '-', '❌' => '!', '👉' => '>', '✓' => '+', '✗' => '!', '►' => '>', '◄' => '<', '▼' => 'v', '▲' => '^' }.freeze
Instance Method Summary collapse
-
#debug(message) ⇒ Object
Log a debug message, converting Unicode to ASCII.
-
#error(message) ⇒ Object
Log an error message, converting Unicode to ASCII.
-
#info(message) ⇒ Object
Log an info message, converting Unicode to ASCII.
-
#initialize(loog) ⇒ AsciiLoog
constructor
Initialize the ASCII wrapper.
-
#method_missing(method) ⇒ Object
Delegate all other methods to the original logger.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if the original logger responds to a method.
-
#to_ascii(message) ⇒ String
Convert Unicode symbols to ASCII equivalents.
-
#warn(message) ⇒ Object
Log a warning message, converting Unicode to ASCII.
Constructor Details
#initialize(loog) ⇒ AsciiLoog
Initialize the ASCII wrapper.
33 34 35 |
# File 'lib/judges/ascii_loog.rb', line 33 def initialize(loog) @loog = loog end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
Delegate all other methods to the original logger.
80 81 82 |
# File 'lib/judges/ascii_loog.rb', line 80 def method_missing(method, *, &) @loog.send(method, *, &) end |
Instance Method Details
#debug(message) ⇒ Object
Log a debug message, converting Unicode to ASCII.
75 76 77 |
# File 'lib/judges/ascii_loog.rb', line 75 def debug() @loog.debug(to_ascii()) end |
#error(message) ⇒ Object
Log an error message, converting Unicode to ASCII.
69 70 71 |
# File 'lib/judges/ascii_loog.rb', line 69 def error() @loog.error(to_ascii()) end |
#info(message) ⇒ Object
Log an info message, converting Unicode to ASCII.
57 58 59 |
# File 'lib/judges/ascii_loog.rb', line 57 def info() @loog.info(to_ascii()) end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if the original logger responds to a method.
85 86 87 |
# File 'lib/judges/ascii_loog.rb', line 85 def respond_to_missing?(method, include_private = false) @loog.respond_to?(method, include_private) || super end |
#to_ascii(message) ⇒ String
Convert Unicode symbols to ASCII equivalents.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/judges/ascii_loog.rb', line 40 def to_ascii() result = .to_s if result.encoding != Encoding::UTF_8 begin result = result.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError result = result.force_encoding(Encoding::UTF_8).encode(Encoding::UTF_8, invalid: :replace, undef: :replace) end end UNICODE_TO_ASCII.each do |unicode, ascii| result = result.gsub(unicode, ascii) end result end |
#warn(message) ⇒ Object
Log a warning message, converting Unicode to ASCII.
63 64 65 |
# File 'lib/judges/ascii_loog.rb', line 63 def warn() @loog.warn(to_ascii()) end |