Sha256: 8698423aee2d6d0a6699f4f84ce8c4753306e398e5ddb44aa1ef44e2e0083d66

Contents?: true

Size: 1.44 KB

Versions: 35

Compression:

Stored size: 1.44 KB

Contents

module Picky

  module Query

    # Combinations are a number of Combination-s.
    #
    # They are the core of an allocation.
    # An allocation consists of a number of combinations.
    #
    # Base Combinations contain methods for calculating score and ids.
    #
    class Combinations # :nodoc:all

      attr_reader :combinations

      delegate :empty?,
               :inject,
               :to => :@combinations

      def initialize combinations = []
        @combinations = combinations
      end

      def hash
        @combinations.hash
      end

      # Uses user specific weights to calculate a score for the combinations.
      #
      def calculate_score weights
        total_score + weighted_score(weights)
      end
      def total_score
        @combinations.sum &:weight
      end
      def weighted_score weights
        weights.score_for @combinations
      end

      # Filters the tokens and categories such that categories
      # that are passed in, are removed.
      #
      # Note: This method is not totally independent of the calculate_ids one.
      #       Since identifiers are only nullified, we need to not include the
      #       ids that have an associated identifier that is nil.
      #
      def remove categories = []
        @combinations.reject! { |combination| categories.include?(combination.category) }
      end

      #
      #
      def to_result
        @combinations.map &:to_result
      end

    end

  end

end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
picky-3.6.10 lib/picky/query/combinations.rb
picky-3.6.9 lib/picky/query/combinations.rb
picky-3.6.8 lib/picky/query/combinations.rb
picky-3.6.7 lib/picky/query/combinations.rb
picky-3.6.6 lib/picky/query/combinations.rb
picky-3.6.4 lib/picky/query/combinations.rb
picky-3.6.3 lib/picky/query/combinations.rb
picky-3.6.2 lib/picky/query/combinations.rb
picky-3.6.1 lib/picky/query/combinations.rb
picky-3.6.0 lib/picky/query/combinations.rb
picky-3.5.4 lib/picky/query/combinations.rb
picky-3.5.3 lib/picky/query/combinations.rb
picky-3.5.2 lib/picky/query/combinations.rb
picky-3.5.1 lib/picky/query/combinations.rb
picky-3.5.0 lib/picky/query/combinations.rb
picky-3.4.3 lib/picky/query/combinations.rb
picky-3.4.2 lib/picky/query/combinations.rb
picky-3.4.1 lib/picky/query/combinations.rb
picky-3.4.0 lib/picky/query/combinations.rb
picky-3.3.3 lib/picky/query/combinations.rb