Class: Julewire::Core::Serialization::TextEncoder
- Inherits:
-
Object
- Object
- Julewire::Core::Serialization::TextEncoder
- Defined in:
- lib/julewire/core/serialization/text_encoder.rb
Constant Summary collapse
- SEVERITY_STYLES =
{ "debug" => 36, "info" => 32, "warn" => 33, "error" => 31, "fatal" => 35, "unknown" => 37 }.freeze
- PUNK_SEVERITY_STYLES =
{ "debug" => 36, "info" => 92, "warn" => 93, "error" => 91, "fatal" => 95, "unknown" => 97 }.freeze
- PUNK_SEVERITY_GLYPHS =
{ "debug" => "..", "info" => ">>", "warn" => "!!", "error" => "XX", "fatal" => "##", "unknown" => "??" }.freeze
- THEMES =
%i[plain punk].freeze
- DEFAULT_MAX_VALUE_BYTES =
160
Class Method Summary collapse
Instance Method Summary collapse
- #call(payload) ⇒ Object
-
#initialize(max_value_bytes: DEFAULT_MAX_VALUE_BYTES, color: false, append_newline: true, theme: :plain) ⇒ TextEncoder
constructor
A new instance of TextEncoder.
Constructor Details
#initialize(max_value_bytes: DEFAULT_MAX_VALUE_BYTES, color: false, append_newline: true, theme: :plain) ⇒ TextEncoder
Returns a new instance of TextEncoder.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/julewire/core/serialization/text_encoder.rb', line 44 def initialize(max_value_bytes: DEFAULT_MAX_VALUE_BYTES, color: false, append_newline: true, theme: :plain) @max_value_bytes = Validation.validate_integer_limit!( max_value_bytes, name: :max_value_bytes, positive: true ) @color = color @line_suffix = append_newline ? "\n" : "" @theme = validate_theme(theme) end |
Class Method Details
.punk_glyph(severity) ⇒ Object
39 40 41 |
# File 'lib/julewire/core/serialization/text_encoder.rb', line 39 def punk_glyph(severity) PUNK_SEVERITY_GLYPHS.fetch(severity.to_s, PUNK_SEVERITY_GLYPHS.fetch("unknown")) end |
Instance Method Details
#call(payload) ⇒ Object
55 56 57 58 |
# File 'lib/julewire/core/serialization/text_encoder.rb', line 55 def call(payload) text = payload.is_a?(String) ? payload : line_for(payload) "#{text}#{@line_suffix}" end |