Class: WavefrontDisplayPrinter::Terse
- Inherits:
-
Object
- Object
- WavefrontDisplayPrinter::Terse
- Defined in:
- lib/wavefront-cli/display/printer/terse.rb
Overview
Print values which are per-row. The terse listings, primarily
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#fmt ⇒ Object
readonly
Returns the value of attribute fmt.
Instance Method Summary collapse
- #format_string(data, keys) ⇒ Object
-
#initialize(data, keys) ⇒ Terse
constructor
A new instance of Terse.
- #map_to_string(value) ⇒ Object
- #stringify(data, keys) ⇒ Object
- #to_s ⇒ Object
- #to_string(value) ⇒ Object
Constructor Details
#initialize(data, keys) ⇒ Terse
Returns a new instance of Terse.
13 14 15 16 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 13 def initialize(data, keys) @data = stringify(data, keys) @fmt = format_string(data, keys) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 8 def data @data end |
#fmt ⇒ Object (readonly)
Returns the value of attribute fmt.
8 9 10 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 8 def fmt @fmt end |
Instance Method Details
#format_string(data, keys) ⇒ Object
18 19 20 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 18 def format_string(data, keys) keys.map { |k| "%-#{data.longest_value_of(k)}<#{k}>s" }.join(' ') end |
#map_to_string(value) ⇒ Object
36 37 38 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 36 def map_to_string(value) format('%s=%s', value.keys[0], value.values.join(',')) end |
#stringify(data, keys) ⇒ Object
22 23 24 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 22 def stringify(data, keys) data.map { |e| e.tap { keys.each { |k| e[k] = to_string(e[k]) } } } end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 40 def to_s data.map { |e| format(fmt, e).rstrip }.join("\n") end |
#to_string(value) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 26 def to_string(value) if value.is_a?(Array) value.join(', ') elsif value.is_a?(Map) map_to_string(value) else value end end |