Sha256: a5494f76d07d0b88cbd60cda3555e64893297162b06f7215a2e9c500deefc2e6

Contents?: true

Size: 757 Bytes

Versions: 2

Compression:

Stored size: 757 Bytes

Contents

# for postgres - select st_asewkt(lon_lat) || st_astext(lon_lat)
# point = @object.class.xselect("ST_AsText(#{field}) as #{field}").where(id: @object.id).first[field.to_sym]

class Typero::PointType < Typero::Type
  def set
    if @value.present?
      if @value.include?('/@')
        point = @value.split('/@', 2).last.split(',')
        @value = [point[0], point[1]].join(',')
      end

      if !@value.include?('POINT') && @value.include?(',')
        point = @value.sub(/,\s*/, ' ')
        @value = 'SRID=4326;POINT(%s)' % point
      end
    end
  end

  def validate
    if @value && @value.include?(',') && !@value =~ /^SRID=4326;POINT\(/
      error_for(:unallowed_characters_error)
    end
  end

  def db_field
    [:geography, {}]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typero-0.8.1 ./lib/typero/type/types/point.rb
typero-0.8.0 ./lib/typero/type/types/point.rb