Sha256: f74f360dbae374d5040cb78228b5b62bddd2b2c00d63486d4511a3119753f2a0

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

module Query

  # Describes the combination of a token (the text) and
  # the index (the bundle).
  #
  # A combination is a single part of an allocation.
  #
  # An allocation consists of a number of combinations.
  #
  class Combination

    attr_reader :token, :bundle

    def initialize token, category
      @token    = token
      @category = category
      @bundle   = category.bundle_for token
      @text     = @token.text # don't want to use reset_similar already
    end
    
    # Note: Required for uniq!
    #
    def hash
      [@token.to_s, @bundle].hash
    end
    
    # Returns the weight of this combination.
    #
    def weight
      @weight || @weight = @bundle.weight(@text)
    end
    
    # Returns an array of ids for the given text.
    #
    def ids
      @ids || @ids = @bundle.ids(@text)
    end
    
    # The identifier for this combination.
    #
    def identifier
      @category.name
    end
    
    # Is the identifier in the given identifiers?
    #
    def in? identifiers
      identifiers.include? identifier
    end

    # Combines the category names with the original names.
    # [
    #  [:title,    'Flarbl', :flarbl],
    #  [:category, 'Gnorf',  :gnorf]
    # ]
    #
    def to_result
      [identifier, *@token.to_result]
    end
    
    # full/title:Flarbl:flarbl
    #
    def to_s
      "#{bundle.name}/#{to_result.join(':')}"
    end
    
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
picky-0.2.2 lib/picky/query/combination.rb
picky-0.2.1 lib/picky/query/combination.rb
picky-0.2.0 lib/picky/query/combination.rb
picky-0.1.0 lib/picky/query/combination.rb
picky-0.0.9 lib/picky/query/combination.rb
picky-0.0.8 lib/picky/query/combination.rb
picky-0.0.7 lib/picky/query/combination.rb
picky-0.0.6 lib/picky/query/combination.rb
picky-0.0.5 lib/picky/query/combination.rb
picky-0.0.4 lib/picky/query/combination.rb
picky-0.0.3 lib/picky/query/combination.rb
picky-0.0.2 lib/picky/query/combination.rb