Sha256: a2672ed4f25a02c9affb4688cb8e59a154b7d0e80b0bf13802b2669b85f93b4c

Contents?: true

Size: 1.01 KB

Versions: 60

Compression:

Stored size: 1.01 KB

Contents

module Inch
  module Evaluation
    # Grades are human-friendly representations of scores.
    #
    class Grade
      extend Utils::ReadWriteMethods

      rw_methods %w(scores label color bg_color)

      def initialize(symbol)
        @symbol = symbol
      end

      # Updates the grade's configuration with the given block
      #
      # @param block [Proc]
      # @return [void]
      def update(&block)
        instance_eval(&block)
      end

      # @return [Symbol] the grade as a symbol (e.g. +:A+)
      def to_sym
        @symbol
      end

      # @return [String] the grade as a string (e.g. "A")
      def to_s
        @symbol.to_s
      end

      class << self
        attr_reader :grade_map

        def all
          @grade_map ||= {}
          @grade_map.values
        end

        def grade(symbol, &block)
          @grade_map ||= {}
          @grade_map[symbol] ||= Grade.new(symbol)
          @grade_map[symbol].update(&block) if block
          @grade_map[symbol]
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 lib/inch/evaluation/grade.rb
inch-0.8.0 lib/inch/evaluation/grade.rb
inch-0.8.0.rc2 lib/inch/evaluation/grade.rb
inch-0.8.0.rc1 lib/inch/evaluation/grade.rb
inch-0.7.1 lib/inch/evaluation/grade.rb
inch-0.7.0 lib/inch/evaluation/grade.rb
inch-0.6.4 lib/inch/evaluation/grade.rb
inch-0.6.3 lib/inch/evaluation/grade.rb
inch-0.6.2 lib/inch/evaluation/grade.rb
inch-0.6.1 lib/inch/evaluation/grade.rb
inch-0.6.0 lib/inch/evaluation/grade.rb
inch-0.6.0.rc6 lib/inch/evaluation/grade.rb
inch-0.6.0.rc5 lib/inch/evaluation/grade.rb
inch-0.6.0.rc4 lib/inch/evaluation/grade.rb
inch-0.6.0.rc3 lib/inch/evaluation/grade.rb
inch-0.6.0.rc2 lib/inch/evaluation/grade.rb
inch-0.6.0.rc1 lib/inch/evaluation/grade.rb
inch-0.5.10 lib/inch/evaluation/grade.rb
inch-0.5.9 lib/inch/evaluation/grade.rb
inch-0.5.8 lib/inch/evaluation/grade.rb