Class: TextPlayer::Formatters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/text_player/formatters/base.rb

Overview

Base formatter with stream writing and common interface

Direct Known Subclasses

Data, Shell, Text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_resultObject (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_hObject

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_sObject

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