Class: Picky::Wrappers::Bundle::Location
- Inherits:
-
Calculation
- Object
- Wrapper
- Calculation
- Picky::Wrappers::Bundle::Location
- 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
Instance Method Summary collapse
-
#add(id, location, where = :unshift) ⇒ Object
Recalculates the added location.
-
#add_partialized(does_not, matter, at_all) ⇒ Object
Do not generate a partial.
- #calculate(float) ⇒ Object
-
#dump ⇒ Object
Save the config, then dump normally.
-
#initialize(bundle, user_grid, options = {}) ⇒ Location
constructor
A new instance of Location.
-
#load ⇒ Object
Load first the bundle, then extract the config.
Methods inherited from Calculation
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, = {} super bundle anchor = [:anchor] || 0.0 precision = [: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 |
#dump ⇒ Object
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 |
#load ⇒ Object
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 |