Class: Kali::Type::Geo
- Inherits:
-
Kali::Type
- Object
- Kali::Type
- Kali::Type::Geo
- Defined in:
- lib/kali/type/geo.rb
Overview
Meta type (not defined in the RFC) for parsing and serializing GeographicPosition properties.
Instance Method Summary collapse
- #decode!(string) ⇒ Object
- #encode!(object) ⇒ Object
-
#initialize(rule = nil) ⇒ Geo
constructor
A new instance of Geo.
Methods inherited from Kali::Type
Constructor Details
#initialize(rule = nil) ⇒ Geo
Returns a new instance of Geo.
5 6 7 8 9 |
# File 'lib/kali/type/geo.rb', line 5 def initialize(rule = nil) super(->(o) { Array === o && o.size == 2 && (rule.nil? || rule === o) }) @latitude = Type::Float.new(-90..90) @longitude = Type::Float.new(-180..180) end |
Instance Method Details
#decode!(string) ⇒ Object
16 17 18 19 |
# File 'lib/kali/type/geo.rb', line 16 def decode!(string) lat, lng = String(string).split(";") [@latitude.decode(lat), @longitude.decode(lng)] end |
#encode!(object) ⇒ Object
11 12 13 14 |
# File 'lib/kali/type/geo.rb', line 11 def encode!(object) [@latitude.encode(object.at(0)), @longitude.encode(object.at(1))].join(";") end |