Sha256: a397b0bb86ef711fe302f395124764488a62a54d6ff48a4871921f85609e2056

Contents?: true

Size: 787 Bytes

Versions: 69

Compression:

Stored size: 787 Bytes

Contents

module Picky

  module Generators

    module Weights
      extend Helpers::Identification
      
      # Factory method to return a fitting
      # weight handling thing for the given thing.
      #  
      def self.from thing, index_name = nil, category_name = nil
        return Default unless thing

        if thing.respond_to? :weight_for
          thing
        elsif thing.respond_to? :to_int
          Logarithmic.new thing
        else
          raise <<-ERROR
weight options #{identifier_for(index_name, category_name)}should be either
* for example a Weights::Logarithmic.new, Weights::Constant.new(int = 0), Weights::Dynamic.new(&block) etc.
or
* an object that responds to #weight_for(amount_of_ids_for_token) => float
ERROR
        end
      end

    end
    
  end
  
end

Version data entries

69 entries across 69 versions & 1 rubygems

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