Class: Stretchy::Boosts::FieldDecayBoost

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/boosts/field_decay_boost.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_DECAY_FN, Base::DEFAULT_WEIGHT

Constants included from Utils::Contract

Utils::Contract::ASSERTIONS, Utils::Contract::DECAY_FUNCTIONS, Utils::Contract::DISTANCE_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Contract

included, #require_one, #validate!

Constructor Details

#initialize(options = {}) ⇒ FieldDecayBoost

Returns a new instance of FieldDecayBoost.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 16

def initialize(options = {})
  @field        = options[:field]
  @origin       = options[:origin]
  @scale        = options[:scale]
  
  @offset       = options[:offset]
  @type         = options[:type]    || DEFAULT_DECAY_FN
  @weight       = options[:weight]  || DEFAULT_WEIGHT
  @decay        = options[:decay]
  
  validate!
end

Instance Attribute Details

#decayObject (readonly)

Returns the value of attribute decay.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def decay
  @decay
end

#decay_amountObject (readonly)

Returns the value of attribute decay_amount.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def decay_amount
  @decay_amount
end

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def field
  @field
end

#offsetObject (readonly)

Returns the value of attribute offset.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def offset
  @offset
end

#originObject (readonly)

Returns the value of attribute origin.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def origin
  @origin
end

#scaleObject (readonly)

Returns the value of attribute scale.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def scale
  @scale
end

#weightObject (readonly)

Returns the value of attribute weight.



8
9
10
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 8

def weight
  @weight
end

Instance Method Details

#to_searchObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 29

def to_search
  json = {scale: @scale}
  if @origin.is_a?(Stretchy::Types::Base)
    json[:origin] = @origin.to_search
  else
    json[:origin] = @origin
  end
  json[:offset] = @offset  if @offset
  json[:decay]  = @decay   if @decay

  {
    @type => {
      @field => json
    },
    weight: @weight
  }
end