Module: Picky::Generators::Weights

Extended by:
Helpers::Identification
Defined in:
lib/picky/generators/weights.rb,
lib/picky/generators/weights/stub.rb,
lib/picky/generators/weights/default.rb,
lib/picky/generators/weights/dynamic.rb,
lib/picky/generators/weights/constant.rb,
lib/picky/generators/weights/strategy.rb,
lib/picky/generators/weights/logarithmic.rb

Defined Under Namespace

Classes: Constant, Dynamic, Logarithmic, Strategy, Stub

Constant Summary collapse

Default =
Logarithmic.new

Class Method Summary collapse

Methods included from Helpers::Identification

identifier_for

Class Method Details

.from(thing, index_name = nil, category_name = nil) ⇒ Object

Factory method to return a fitting weight handling thing for the given thing.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/picky/generators/weights.rb', line 11

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