Sha256: 53bc609dc5db71e67848de0f4243aa39474619b68a15f28e33d1e9501d15c304

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Picky

    module Wrappers

      module Bundle

        # A location calculation recalculates a location to the Picky internal location.
        #
        class Location < Calculation

          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

          #
          #
          def calculate float
            @calculation.calculate float
          end

          # Recalculates the added location.
          #
          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

          # Do not generate a partial.
          #
          def add_partialized does_not, matter, at_all
            # Nothing
          end

          # Save the config, then dump normally.
          #
          def dump
            bundle[:location_anchor] = @calculation.anchor

            bundle.dump
          end

          # Load first the bundle, then extract the config.
          #
          def load
            bundle.load

            # TODO Symbols (of the location_anchor!!!).
            # It should always be a Symbol.
            #
            @calculation.anchor = bundle['location_anchor'] && bundle['location_anchor'].to_f || raise("Configuration 'location_anchor' for #{bundle.identifier} missing. Did you run rake index already?")
          end

        end

      end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-4.0.0pre2 lib/picky/wrappers/bundle/location.rb