Class: WavefrontDisplayPrinter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-cli/display/printer/base.rb

Overview

Base class for the two printer classes

Direct Known Subclasses

Long, Terse

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outObject (readonly)

Returns the value of attribute out.



6
7
8
# File 'lib/wavefront-cli/display/printer/base.rb', line 6

def out
  @out
end

Instance Method Details

#key_width(hash = {}, pad = 3) ⇒ Integer

Give it a key-value hash, and it will return the size of the first column to use when formatting that data.

Parameters:

  • hash (Hash) (defaults to: {})

    the data for which you need a column width

  • pad (Integer) (defaults to: 3)

    the number of spaces you want between columns

Returns:

  • (Integer)

    length of longest key + pad



15
16
17
18
# File 'lib/wavefront-cli/display/printer/base.rb', line 15

def key_width(hash = {}, pad = 3)
  return 0 if hash.keys.empty?
  hash.keys.map(&:size).max + pad
end

#to_sObject



20
21
22
# File 'lib/wavefront-cli/display/printer/base.rb', line 20

def to_s
  out.join("\n")
end