Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Point

Inherits:
Type::Value
  • Object
show all
Includes:
Type::Mutable
Defined in:
lib/active_record/connection_adapters/postgresql/oid/point.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Type::Mutable

#changed_in_place?, #type_cast_from_user

Methods inherited from Type::Value

#==, #binary?, #changed?, #changed_in_place?, #hash, #initialize, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_database, #type_cast_from_user

Constructor Details

This class inherits a constructor from ActiveRecord::Type::Value

Instance Method Details

#typeObject



8
9
10
# File 'lib/active_record/connection_adapters/postgresql/oid/point.rb', line 8

def type
  :point
end

#type_cast(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_record/connection_adapters/postgresql/oid/point.rb', line 12

def type_cast(value)
  case value
  when ::String
    if value[0] == '(' && value[-1] == ')'
      value = value[1...-1]
    end
    type_cast(value.split(','))
  when ::Array
    value.map { |v| Float(v) }
  else
    value
  end
end

#type_cast_for_database(value) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/active_record/connection_adapters/postgresql/oid/point.rb', line 26

def type_cast_for_database(value)
  if value.is_a?(::Array)
    "(#{number_for_point(value[0])},#{number_for_point(value[1])})"
  else
    super
  end
end