Class: Console::Output::Encoder
- Inherits:
-
Object
- Object
- Console::Output::Encoder
- Defined in:
- lib/console/output/encoder.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #call(subject = nil, *arguments, **options, &block) ⇒ Object
- #encode(value) ⇒ Object
-
#initialize(output, encoding = ::Encoding::UTF_8) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(output, encoding = ::Encoding::UTF_8) ⇒ Encoder
Returns a new instance of Encoder.
9 10 11 12 |
# File 'lib/console/output/encoder.rb', line 9 def initialize(output, encoding = ::Encoding::UTF_8) @output = output @encoding = encoding end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
16 17 18 |
# File 'lib/console/output/encoder.rb', line 16 def encoding @encoding end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/console/output/encoder.rb', line 14 def output @output end |
Instance Method Details
#call(subject = nil, *arguments, **options, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/console/output/encoder.rb', line 18 def call(subject = nil, *arguments, **, &block) subject = encode(subject) arguments = encode(arguments) = encode() @output.call(subject, *arguments, **, &block) end |
#encode(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/console/output/encoder.rb', line 26 def encode(value) case value when String value.encode(@encoding, invalid: :replace, undef: :replace) when Array value.map{|item| encode(item)} when Hash value.transform_values{|item| encode(item)} else value end end |