Module: AllegroGraph::Utility::ParameterMapper

Defined in:
lib/allegro_graph/utility/parameter_mapper.rb

Constant Summary collapse

MAP =
{
  :strip_width    => { :to => :stripWidth,  :for => [ :cartesian_type, :spherical_type ], :default => 1 },
  :x_min          => { :to => :xmin,        :for => [ :cartesian_type, :find_inside_box ] },
  :y_min          => { :to => :ymin,        :for => [ :cartesian_type, :find_inside_box ] },
  :x_max          => { :to => :xmax,        :for => [ :cartesian_type, :find_inside_box ] },
  :y_max          => { :to => :ymax,        :for => [ :cartesian_type, :find_inside_box ] },
  :unit           => { :to => :unit,        :for => [ :spherical_type, :find_inside_haversine ], :default => :degree },
  :latitude_min   => { :to => :latmin,      :for => [ :spherical_type ] },
  :longitude_min  => { :to => :longmin,     :for => [ :spherical_type ] },
  :latitude_max   => { :to => :latmax,      :for => [ :spherical_type ] },
  :longitude_max  => { :to => :longmax,     :for => [ :spherical_type ] },
  :name           => { :to => :resource,    :for => [ :create_polygon ], :modifier => [ :quote ] },
  :type           => { :to => :type,        :for => [ :find_inside_box, :find_inside_circle, :find_inside_haversine, :find_inside_polygon ] },
  :predicate      => { :to => :predicate,   :for => [ :find_inside_box, :find_inside_circle, :find_inside_haversine, :find_inside_polygon ] },
  :x              => { :to => :x,           :for => [ :find_inside_circle ] },
  :y              => { :to => :y,           :for => [ :find_inside_circle ] },
  :radius         => { :to => :radius,      :for => [ :find_inside_circle, :find_inside_haversine ] },
  :latitude       => { :to => :lat,         :for => [ :find_inside_haversine ], :modifier => :latitude_to_iso },
  :longitude      => { :to => :long,        :for => [ :find_inside_haversine ], :modifier => :longitude_to_iso },
  :polygon_name   => { :to => :polygon,     :for => [ :find_inside_polygon ], :modifier => [ :quote ] }
}.freeze

Class Method Summary collapse

Class Method Details

.latitude_to_iso(value) ⇒ Object



53
54
55
# File 'lib/allegro_graph/utility/parameter_mapper.rb', line 53

def self.latitude_to_iso(value)
  float_to_iso value, 2
end

.longitude_to_iso(value) ⇒ Object



57
58
59
# File 'lib/allegro_graph/utility/parameter_mapper.rb', line 57

def self.longitude_to_iso(value)
  float_to_iso value, 3
end

.map(parameters, method_name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/allegro_graph/utility/parameter_mapper.rb', line 30

def self.map(parameters, method_name)
  result = { }
  MAP.each do |key, mapping|
    value = parameters[key] || mapping[:default]
    required = [ mapping[:for] ].flatten.include? method_name.to_sym
    if required
      if value
        [ mapping[:modifier] ].flatten.compact.each do |modifier|
          value = send modifier, value
        end
        result[ mapping[:to] ] = value.to_s
      else
        raise ArgumentError, "missing parameter :#{key}!"
      end
    end
  end
  result
end

.quote(value) ⇒ Object



49
50
51
# File 'lib/allegro_graph/utility/parameter_mapper.rb', line 49

def self.quote(value)
  "\"#{value}\""
end