Method: HaveAPI::CLI::OutputFormatter#initialize
- Defined in:
- lib/haveapi/cli/output_formatter.rb
#initialize(objects, cols = nil, header: true, sort: nil, layout: nil, empty: '-') ⇒ OutputFormatter
Returns a new instance of OutputFormatter.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/haveapi/cli/output_formatter.rb', line 13 def initialize(objects, cols = nil, header: true, sort: nil, layout: nil, empty: '-') @objects = objects @header = header @sort = sort @layout = layout @empty = empty if @layout.nil? if many? @layout = :columns else @layout = :rows end end if cols @cols = parse_cols(cols) else if @objects.is_a?(::Array) # A list of items @cols ||= parse_cols(@objects.first.keys) elsif @objects.is_a?(::Hash) # Single item @cols ||= parse_cols(@objects.keys) else fail "unsupported type #{@objects.class}" end end end |