Class: HammerCLI::Output::Adapter::Table
- Inherits:
-
Abstract
- Object
- Abstract
- HammerCLI::Output::Adapter::Table
show all
- Defined in:
- lib/hammer_cli/output/adapter/table.rb
Constant Summary
collapse
- MAX_COLUMN_WIDTH =
80
- MIN_COLUMN_WIDTH =
5
- HLINE =
'-'
- LINE_SEPARATOR =
'-|-'
- COLUMN_SEPARATOR =
' | '
Instance Method Summary
collapse
Methods inherited from Abstract
#initialize, #paginate_by_default?, #print_error, #print_message
Instance Method Details
#print_collection(all_fields, collection) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/hammer_cli/output/adapter/table.rb', line 23
def print_collection(all_fields, collection)
fields = field_filter.filter(all_fields)
fields = displayable_fields(fields, collection.first, compact_only: true)
formatted_collection = format_values(fields, collection)
widths = calculate_widths(fields, formatted_collection)
= []
hline_bits = []
fields.map do |f|
<< normalize_column(widths[f.label], f.label.upcase)
hline_bits << HLINE * widths[f.label]
end
line = hline_bits.join(LINE_SEPARATOR)
unless @context[:no_headers]
output_stream.puts line
output_stream.puts .join(COLUMN_SEPARATOR)
output_stream.puts line
end
formatted_collection.collect do |row|
row_bits = fields.map do |f|
normalize_column(widths[f.label], row[f.label] || "")
end
output_stream.puts row_bits.join(COLUMN_SEPARATOR)
end
output_stream.puts line unless formatted_collection.empty? || @context[:no_headers]
if collection.respond_to?(:meta) && collection.meta. && collection.count < collection.meta.subtotal
pages = (collection.meta.subtotal.to_f/collection.meta.per_page).ceil
puts _("Page %{page} of %{total} (use --page and --per-page for navigation).") % {:page => collection.meta.page, :total => pages}
end
end
|
#print_record(fields, record) ⇒ Object
19
20
21
|
# File 'lib/hammer_cli/output/adapter/table.rb', line 19
def print_record(fields, record)
print_collection(fields, [record].flatten(1))
end
|
15
16
17
|
# File 'lib/hammer_cli/output/adapter/table.rb', line 15
def tags
[:screen, :flat]
end
|