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 =
{ '👍' => '+', '👎' => '-', '❌' => '!', '👉' => '>', '✓' => '+', '✗' => '!', '►' => '>', '◄' => '<', '▼' => '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.
32 33 34 |
# File 'lib/judges/ascii_loog.rb', line 32 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.
79 80 81 |
# File 'lib/judges/ascii_loog.rb', line 79 def method_missing(method, *, &) @loog.public_send(method, *, &) end |
Instance Method Details
#debug(message) ⇒ Object
Log a debug message, converting Unicode to ASCII.
74 75 76 |
# File 'lib/judges/ascii_loog.rb', line 74 def debug() @loog.debug(to_ascii()) end |
#error(message) ⇒ Object
Log an error message, converting Unicode to ASCII.
68 69 70 |
# File 'lib/judges/ascii_loog.rb', line 68 def error() @loog.error(to_ascii()) end |
#info(message) ⇒ Object
Log an info message, converting Unicode to ASCII.
56 57 58 |
# File 'lib/judges/ascii_loog.rb', line 56 def info() @loog.info(to_ascii()) end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if the original logger responds to a method.
84 85 86 |
# File 'lib/judges/ascii_loog.rb', line 84 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.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/judges/ascii_loog.rb', line 39 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.
62 63 64 |
# File 'lib/judges/ascii_loog.rb', line 62 def warn() @loog.warn(to_ascii()) end |