Sha256: b1ea1201cc37b85c7ec381508f1d7a3e272af130ece0c51af3a5042fc67635f7

Contents?: true

Size: 899 Bytes

Versions: 8

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

require 'terminal-table'

module RubyPGExtras
  class DiagnosePrint
    def self.call(data)
      new.call(data)
    end

    def call(data)
      rows = data.sort do |el|
        el.fetch(:ok) ? 1 : -1
      end.map do |el|
        symbol = el.fetch(:ok) ? "√" : "x"
        color = el.fetch(:ok) ? :green : :red

        [
          colorize("[#{symbol}] - #{el.fetch(:check_name)}", color),
          colorize(el.fetch(:message), color)
        ]
      end

      puts Terminal::Table.new(
        title: title,
        rows: rows
      )
    end

    private

    def title
      "ruby-pg-extras - diagnose report"
    end

    def colorize(string, color)
      if color == :red
        "\e[0;31;49m#{string}\e[0m"
      elsif color == :green
        "\e[0;32;49m#{string}\e[0m"
      else
        raise "Unsupported color: #{color}"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby-pg-extras-3.3.0 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.7 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.6 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.5 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.4 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.3 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.2 lib/ruby-pg-extras/diagnose_print.rb
ruby-pg-extras-3.2.1 lib/ruby-pg-extras/diagnose_print.rb