Sha256: c305aa5463e27f7d533941c514a77b178f5861b52efdb7e1134b850e3335f66d

Contents?: true

Size: 1.19 KB

Versions: 45

Compression:

Stored size: 1.19 KB

Contents

require 'table_print'

module PactBroker
  module Client
    class Matrix
      class TextFormatter

        Line = Struct.new(:consumer, :consumer_version, :provider, :provider_version, :success)

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

        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

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

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pact_broker-client-1.34.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.33.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.32.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.31.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.30.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.29.1 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.29.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.28.4 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.28.3 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.28.2 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.28.1 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.28.0 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.28 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.27 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.26 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.25 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.24 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.23 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.22 lib/pact_broker/client/matrix/text_formatter.rb
pact_broker-client-1.27.21 lib/pact_broker/client/matrix/text_formatter.rb