Class: TextPlayer::Formatters::Base
- Inherits:
-
Object
- Object
- TextPlayer::Formatters::Base
- Defined in:
- lib/text_player/formatters/base.rb
Overview
Base formatter with stream writing and common interface
Instance Attribute Summary collapse
-
#command_result ⇒ Object
readonly
Returns the value of attribute command_result.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(command_result) ⇒ Base
constructor
A new instance of Base.
-
#to_h ⇒ Object
Hash representation for programmatic access.
-
#to_s ⇒ Object
String representation for stream output.
-
#write(stream) ⇒ Object
Write formatted output to stream.
Constructor Details
#initialize(command_result) ⇒ Base
Returns a new instance of Base.
15 16 17 |
# File 'lib/text_player/formatters/base.rb', line 15 def initialize(command_result) @command_result = command_result end |
Instance Attribute Details
#command_result ⇒ Object (readonly)
Returns the value of attribute command_result.
13 14 15 |
# File 'lib/text_player/formatters/base.rb', line 13 def command_result @command_result end |
Class Method Details
.write(command_result, stream) ⇒ Object
9 10 11 |
# File 'lib/text_player/formatters/base.rb', line 9 def self.write(command_result, stream) new(command_result).write(stream) end |
Instance Method Details
#to_h ⇒ Object
Hash representation for programmatic access
30 31 32 |
# File 'lib/text_player/formatters/base.rb', line 30 def to_h command_result.to_h end |
#to_s ⇒ Object
String representation for stream output
25 26 27 |
# File 'lib/text_player/formatters/base.rb', line 25 def to_s command_result.to_h.inspect end |
#write(stream) ⇒ Object
Write formatted output to stream
20 21 22 |
# File 'lib/text_player/formatters/base.rb', line 20 def write(stream) stream.write(to_s) end |