Module: Ec2spec::Formatter::PlainTextFormatter

Included in:
MarkdownFormatter, SlackFormatter
Defined in:
lib/ec2spec/formatter/plain_text_formatter.rb

Instance Method Summary collapse

Instance Method Details

#output(results, hosts) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/ec2spec/formatter/plain_text_formatter.rb', line 4

def output(results, hosts)
  table = Terminal::Table.new
  table.headings = table_header(results)
  table.rows = table_rows(results)
  column_count = hosts.size + 1
  column_count.times { |i| table.align_column(i, :right) }
  table
end

#table_header(results) ⇒ Object



13
14
15
# File 'lib/ec2spec/formatter/plain_text_formatter.rb', line 13

def table_header(results)
  [''].concat(results.map(&:host))
end

#table_rows(results) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/ec2spec/formatter/plain_text_formatter.rb', line 17

def table_rows(results)
  Ec2spec::HostResult.label_with_methods
                     .each_with_object([]) do |(k, v), row|
    unit = PriceCalculator.instance.currency_unit
    label = format(k, unit)
    row << [label].concat(results.map(&v))
  end
end