Class: PactBroker::Client::Matrix::TextFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/matrix/text_formatter.rb

Defined Under Namespace

Classes: Line

Constant Summary collapse

OPTIONS =
[
  { consumer: {} },
  { consumer_version: {display_name: 'C.VERSION'} },
  { provider: {} },
  { provider_version: {display_name: 'P.VERSION'} },
  { success: {display_name: 'SUCCESS?'} }
]

Class Method Summary collapse

Class Method Details

.call(matrix) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pact_broker/client/matrix/text_formatter.rb', line 18

def self.call(matrix)
  matrix_rows = matrix[:matrix]
  return "" if matrix_rows.size == 0
  data = matrix_rows.collect do | line |
    Line.new(
      lookup(line, :consumer, :name),
      lookup(line, :consumer, :version, :number),
      lookup(line, :provider, :name),
      lookup(line, :provider, :version, :number),
      lookup(line, :verificationResult, :success).to_s
    )
  end

  printer = TablePrint::Printer.new(data, OPTIONS)
  printer.table_print
end

.lookup(line, *keys) ⇒ Object



35
36
37
38
39
# File 'lib/pact_broker/client/matrix/text_formatter.rb', line 35

def self.lookup line, *keys
  keys.reduce(line) { | line, key | line[key] }
rescue NoMethodError
  "???"
end