Sha256: 1890e4bc8418bde0165adbbc674d92e87ea5dfdfdb61244b467d09731feebe60

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 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, options = {}
            super bundle

            user_grid  = options[:grid]      || raise("Gridsize needs to be given for location #{bundle.identifier}.")
            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!!!).
            #
            @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

5 entries across 5 versions & 1 rubygems

Version Path
picky-3.5.4 lib/picky/wrappers/bundle/location.rb
picky-3.5.3 lib/picky/wrappers/bundle/location.rb
picky-3.5.2 lib/picky/wrappers/bundle/location.rb
picky-3.5.1 lib/picky/wrappers/bundle/location.rb
picky-3.5.0 lib/picky/wrappers/bundle/location.rb