Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cube
- Inherits:
-
Point
- Object
- Point
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cube
- Defined in:
- lib/postgresql-cube/type.rb
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/postgresql-cube/type.rb', line 12 def cast(value) case value when ::String dimensions = value.scan(/\(([^)]+)\)/).flatten.map { |dimension| dimension.split(/ *, */) } cast(dimensions.many? ? dimensions : dimensions[0]) when ::Array value.map { |v| v.is_a?(::Array) ? cast(v) : Float(v) } else value end end |
#serialize(value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/postgresql-cube/type.rb', line 24 def serialize(value) if value.is_a?(::Array) values = value.map { |v| v.is_a?(::Array) ? serialize(v) : Float(v) } values = values.join(',') values = "(#{values})" unless values[0] == '(' && values[-1] == ')' values else super end end |
#type ⇒ Object
8 9 10 |
# File 'lib/postgresql-cube/type.rb', line 8 def type :cube end |