class Superstore::Types::GeoPointType

Public Instance Methods

cast_value(value) click to toggle source
# File lib/superstore/types/geo_point_type.rb, line 10
def cast_value(value)
  case value
  when String
    cast_value value.split(/[,\s]+/)
  when Array
    to_float_or_nil(lat: value[0], lon: value[1])
  when Hash
    to_float_or_nil(lat: value[:lat] || value['lat'], lon: value[:lon] || value['lon'])
  end
end
deserialize(value) click to toggle source
# File lib/superstore/types/geo_point_type.rb, line 6
def deserialize(value)
  {lat: value[:lat] || value['lat'], lon: value[:lon] || value['lon']} if value
end

Private Instance Methods

to_float_or_nil(coords) click to toggle source
# File lib/superstore/types/geo_point_type.rb, line 23
def to_float_or_nil(coords)
  if coords[:lat] && coords[:lon]
    coords.transform_values!(&:to_f)
  end
end