Sha256: 027660cefae49ceba5651cf5b8a106b2e2377c9254f9a292c3de5b4f0c741157

Contents?: true

Size: 902 Bytes

Versions: 4

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

require 'rainbow'

module RubyCritic
  module Generator
    module Text
      class List
        class << self
          TEMPLATE_PATH = File.expand_path('../templates/list.erb', __FILE__)

          def erb_template
            @erb_template ||= ERB.new(File.read(TEMPLATE_PATH), nil, '-')
          end
        end

        RATING_TO_COLOR = {
          'A' => :green,
          'B' => :green,
          'C' => :yellow,
          'D' => :orange,
          'F' => :red
        }.freeze

        def initialize(analysed_module)
          @analysed_module = analysed_module
        end

        def render
          erb_template.result(binding)
        end

        private

        def erb_template
          self.class.erb_template
        end

        def color
          @color ||= RATING_TO_COLOR[@analysed_module.rating.to_s]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubycritic-3.3.0 lib/rubycritic/generators/text/list.rb
rubycritic-3.2.3 lib/rubycritic/generators/text/list.rb
rubycritic-3.2.2 lib/rubycritic/generators/text/list.rb
rubycritic-3.2.1 lib/rubycritic/generators/text/list.rb