Class: Typero::SimplePointType

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

Overview

Same as point, but we keep data as a float in Array

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



18
19
20
# File 'lib/typero/type/types/simple_point_type.rb', line 18

def db_schema
  [:float, { array: true }]
end

#setObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/typero/type/types/simple_point_type.rb', line 4

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

  if !value.include?('POINT') && value.include?(',')
    value { value.split(/\s*,\s*/)[0,2] }
  end

  # value { value.map { sprintf("%.16f", _1).to_f } }
end