Class: Picky::Wrappers::Bundle::Location

Inherits:
Calculation show all
Defined in:
lib/picky/wrappers/bundle/location.rb

Overview

A location calculation recalculates a location to the Picky internal location.

Instance Attribute Summary

Attributes inherited from Wrapper

#bundle

Instance Method Summary collapse

Methods inherited from Calculation

#ids, #weight

Constructor Details

#initialize(bundle, user_grid, options = {}) ⇒ Location

Returns a new instance of Location.



11
12
13
14
15
16
17
18
# File 'lib/picky/wrappers/bundle/location.rb', line 11

def initialize bundle, user_grid, options = {}
  super bundle

  anchor     = options[:anchor]    || 0.0
  precision  = options[:precision] || 1

  @calculation = Calculations::Location.new user_grid, anchor, precision
end

Instance Method Details

#add(id, location, where = :unshift) ⇒ Object

Recalculates the added location.



28
29
30
31
32
# File 'lib/picky/wrappers/bundle/location.rb', line 28

def add id, location, where = :unshift
  @calculation.calculated_range(location.to_s.to_f).each do |new_location|
    bundle.add id, new_location.to_s, where
  end
end

#add_partialized(does_not, matter, at_all) ⇒ Object

Do not generate a partial.



36
37
38
# File 'lib/picky/wrappers/bundle/location.rb', line 36

def add_partialized does_not, matter, at_all
  # Nothing
end

#calculate(float) ⇒ Object



22
23
24
# File 'lib/picky/wrappers/bundle/location.rb', line 22

def calculate float
  @calculation.calculate float
end

#dumpObject

Save the config, then dump normally.



42
43
44
45
46
# File 'lib/picky/wrappers/bundle/location.rb', line 42

def dump
  bundle['location_anchor'] = @calculation.anchor

  bundle.dump
end

#loadObject

Load first the bundle, then extract the config.



50
51
52
53
54
55
# File 'lib/picky/wrappers/bundle/location.rb', line 50

def load
  bundle.load

  location_anchor     = bundle['location_anchor']
  @calculation.anchor = location_anchor && location_anchor.to_f || raise("Configuration 'location_anchor' for #{bundle.identifier} missing. Did you run rake index already?")
end