Sha256: 9a9dda96cdfd54076bc63962f7988039567ca3ffb0c05f182c81fe22301cd97c
Contents?: true
Size: 732 Bytes
Versions: 1
Compression:
Stored size: 732 Bytes
Contents
# frozen_string_literal: true module Superstore module Types class GeoPointType < ActiveModel::Type::Value def deserialize(value) {lat: value[:lat] || value['lat'], lon: value[:lon] || value['lon']} if value end 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 private def to_float_or_nil(coords) if coords[:lat] && coords[:lon] coords.transform_values!(&:to_f) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
superstore-2.5.0 | lib/superstore/types/geo_point_type.rb |