Class: Typero::PointType

Inherits:
Type
  • Object
show all
Defined in:
lib/typero/type/types/point_type.rb

Overview

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

Constant Summary

Constants inherited from Type

Type::ERRORS, Type::OPTS, Type::OPTS_KEYS

Instance Attribute Summary

Attributes inherited from Type

#opts

Instance Method Summary collapse

Methods inherited from Type

allowed_opt?, #db_field, db_schema, #default, error, #get, #initialize, load, opts, #value

Constructor Details

This class inherits a constructor from Typero::Type

Instance Method Details

#db_schemaObject



22
23
24
# File 'lib/typero/type/types/point_type.rb', line 22

def db_schema
  [:geography, {}]
end

#setObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/typero/type/types/point_type.rb', line 5

def set
  if value.include?('/@')
    # extract value from google maps link
    point = value.split('/@', 2).last.split(',')
    value { [point[0], point[1]].join(',') }
  end

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

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