Sha256: 6c79be8b5b3edcff47629f8c00ca85027b02ecd5f198c927d8ac2d32c11bd0b2

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

module Inch
  module CLI
    module Command
      module Output
        class Show < Base
          attr_reader :objects

          COLOR = :color132
          BG_COLOR = :color138
          LJUST = 20

          def initialize(options, objects)
            @options = options
            @objects = objects

            display_objects
          end

          private

          def display_objects
            objects.each do |o|
              print_object(o)
            end
          end

          def print_object(o)
            trace
            trace_header(o.fullname, COLOR, BG_COLOR)

            print_file_info(o, COLOR)
            print_grade_info(o)
            print_roles_info(o)
          end

          def print_grade_info(o)
            echo "Grade: #{grade(o.score)}".rjust(5)
            echo separator
          end

          def print_roles_info(o)
            if o.roles.empty?
              echo "No roles assigned.".dark
            else
              o.roles.each_with_index do |role, index|
                if role.suggestion
                  echo "+".color(COLOR) + " #{role.suggestion}"
                end
              end
            end
            echo separator
          end

          def echo(msg = "")
            trace edged(COLOR, msg)
          end

          def separator
            "-".color(COLOR) * (CLI::COLUMNS - 2)
          end

          def grade(score)
            grade_lists ||= Evaluation.new_grade_lists
            r = grade_lists.detect { |r| r.scores.include?(score) }
            "#{r.grade} - #{r.label}".color(r.color)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inch-0.3.0 lib/inch/cli/command/output/show.rb
inch-0.3.0.rc3 lib/inch/cli/command/output/show.rb
inch-0.3.0.rc2 lib/inch/cli/command/output/show.rb
inch-0.3.0.rc1 lib/inch/cli/command/output/show.rb