Sha256: 2f6e10f5cf58d68347c4ff19e099548a3092cd43552565936bb839ae8248b8e9

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Inch
  module Evaluation
    # @abstract
    class Base
      extend Forwardable

      MIN_SCORE = 0
      MAX_SCORE = 100

      TAGGED_SCORE = 20 # assigned per unconsidered tag


      attr_accessor :object
      attr_reader :min_score, :max_score

      def initialize(object)
        self.object = object
        @roles = []
        evaluate
      end

      def evaluate
      end

      def max_score
        arr = @roles.map(&:max_score).compact
        [MAX_SCORE].concat(arr).min
      end

      def min_score
        arr = @roles.map(&:min_score).compact
        [MIN_SCORE].concat(arr).max
      end

      def score
        value = @roles.inject(0) { |sum,r| sum + r.score.to_f }
        if value < min_score
          min_score
        elsif value > max_score
          max_score
        else
          value
        end
      end

      def priority
        @roles.inject(0) { |sum,r| sum + r.priority.to_i }
      end

      def roles
        @roles
      end

      protected

      def add_role(role)
        @roles << role
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inch-0.1.4 lib/inch/evaluation/base.rb