Class: WavefrontDisplayPrinter::Terse
- Inherits:
-
Object
- Object
- WavefrontDisplayPrinter::Terse
- Defined in:
- lib/wavefront-cli/display/printer/terse.rb
Overview
Print things 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.
- #stringify(data, keys) ⇒ Object
- #to_list(thing) ⇒ Object
- #to_s ⇒ 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 |
#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_list(e[k]) } } } end |
#to_list(thing) ⇒ Object
26 27 28 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 26 def to_list(thing) thing.is_a?(Array) ? thing.join(', ') : thing end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/wavefront-cli/display/printer/terse.rb', line 30 def to_s data.map { |e| format(fmt, e).rstrip }.join("\n") end |