Sha256: 955f0ee8d10291648ccc5c8cc1448603d7b1ee0d1a259966bb49fa84d6f88037

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

module Picky

  module Query

    # Combinations represent an ordered list of Combination s.
    #
    # Combinations contain methods for calculating score (including
    # the boost) and ids for each of its Combination s.
    #
    # They are the core of an Allocation.
    # An Allocation consists of a number of Combinations.
    #
    class Combinations

      attr_reader :combinations

      forward :empty?,
              :inject,
              :map,
              :to => :@combinations

      def initialize combinations = []
        @combinations = combinations
      end

      # TODO
      #
      def each &block
        @combinations.each &block
      end

      # Sums up the weights of the combinations.
      #
      # Note: Optimized sum(&:weight) away – ~3% improvement.
      #
      def score
        @combinations.inject(0) { |total, combination| total + combination.weight }
      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 = []
        # TODO Do not use the name, but the category.
        #
        @combinations.reject! { |combination| categories.include?(combination.category_name) }
      end

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

      def to_qualifiers
        @combinations.map &:category_name
      end

      #
      #
      def to_s
        @combinations.to_s
      end

    end

  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
picky-4.31.3 lib/picky/query/combinations.rb
picky-4.31.2 lib/picky/query/combinations.rb
picky-4.31.1 lib/picky/query/combinations.rb
picky-4.31.0 lib/picky/query/combinations.rb
picky-4.30.0 lib/picky/query/combinations.rb
picky-4.29.0 lib/picky/query/combinations.rb
picky-4.28.1 lib/picky/query/combinations.rb
picky-4.27.1 lib/picky/query/combinations.rb
picky-4.27.0 lib/picky/query/combinations.rb
picky-4.26.2 lib/picky/query/combinations.rb
picky-4.26.1 lib/picky/query/combinations.rb
picky-4.26.0 lib/picky/query/combinations.rb
picky-4.25.3 lib/picky/query/combinations.rb
picky-4.25.2 lib/picky/query/combinations.rb
picky-4.25.1 lib/picky/query/combinations.rb
picky-4.25.0 lib/picky/query/combinations.rb
picky-4.24.0 lib/picky/query/combinations.rb
picky-4.23.2 lib/picky/query/combinations.rb