Sha256: 60780cf51d3d761cc4fa4c29455a45dbb042983a4273669c24e1a8cefce92358

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 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

      def score
        @combinations.sum &:weight
      end
      def boost_for weights
        weights.boost_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

      #
      #
      def to_s
        @combinations.to_s
      end

    end

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
picky-4.4.1 lib/picky/query/combinations.rb
picky-4.4.0 lib/picky/query/combinations.rb
picky-4.3.2 lib/picky/query/combinations.rb
picky-4.3.1 lib/picky/query/combinations.rb
picky-4.3.0 lib/picky/query/combinations.rb
picky-4.2.4 lib/picky/query/combinations.rb
picky-4.2.3 lib/picky/query/combinations.rb
picky-4.2.2 lib/picky/query/combinations.rb
picky-4.2.1 lib/picky/query/combinations.rb
picky-4.2.0 lib/picky/query/combinations.rb
picky-4.1.0 lib/picky/query/combinations.rb
picky-4.0.9 lib/picky/query/combinations.rb
picky-4.0.8 lib/picky/query/combinations.rb
picky-4.0.7 lib/picky/query/combinations.rb
picky-4.0.6 lib/picky/query/combinations.rb
picky-4.0.5 lib/picky/query/combinations.rb
picky-4.0.4 lib/picky/query/combinations.rb
picky-4.0.3 lib/picky/query/combinations.rb
picky-4.0.1 lib/picky/query/combinations.rb
picky-4.0.0 lib/picky/query/combinations.rb