Class: HammerCLI::Output::Adapter::Table

Inherits:
Abstract
  • Object
show all
Defined in:
lib/hammer_cli/output/adapter/table.rb

Instance Method Summary collapse

Methods inherited from Abstract

#initialize, #print_error, #print_message

Constructor Details

This class inherits a constructor from HammerCLI::Output::Adapter::Abstract

Instance Method Details



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
# File 'lib/hammer_cli/output/adapter/table.rb', line 15

def print_collection(all_fields, collection)

  fields = all_fields.reject { |f| f.class <= Fields::Id && !@context[:show_ids] }

  rows = collection.collect do |d|
    row = {}
    fields.each do |f|
      row[f.label.to_sym] = f.get_value(d) || ""
    end
    row
  end

  options = fields.collect do |f|
    { f.label.to_sym => { :formatters => Array(@formatters.formatter_for_type(f.class)) } }
  end

  sort_order = fields.map { |f| f.label.upcase }

  printer = TablePrint::Printer.new(rows, options)
  TablePrint::Config.max_width = 40

  output = sort_columns(printer.table_print, sort_order)
  dashes = /\n([-|]+)\n/.match(output)

  puts dashes[1] if dashes
  puts output
  puts dashes[1] if dashes
end


44
45
46
47
48
49
# File 'lib/hammer_cli/output/adapter/table.rb', line 44

def print_heading(heading, size)
  size = heading.size if heading.size > size
  puts '-' * size
  puts ' ' * ((size-heading.size)/2) + heading
  puts '-' * size
end


11
12
13
# File 'lib/hammer_cli/output/adapter/table.rb', line 11

def print_record(fields, record)
  print_collection(fields, [record].flatten(1))
end

#tagsObject



7
8
9
# File 'lib/hammer_cli/output/adapter/table.rb', line 7

def tags
  [:screen, :flat]
end