Class: Parse::GeoPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/datatypes.rb

Overview

GeoPoint


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ GeoPoint

Returns a new instance of GeoPoint.



228
229
230
231
232
233
234
235
236
# File 'lib/parse/datatypes.rb', line 228

def initialize(data)
  @longitude = data["longitude"]
  @latitude  = data["latitude"]

  if !@longitude && !@latitude
    @longitude = data[:longitude]
    @latitude  = data[:latitude]
  end
end

Instance Attribute Details

#latitudeObject

‘{“__type”:“GeoPoint”, “latitude”:40.0, “longitude”:-30.0}’



226
227
228
# File 'lib/parse/datatypes.rb', line 226

def latitude
  @latitude
end

#longitudeObject

‘{“__type”:“GeoPoint”, “latitude”:40.0, “longitude”:-30.0}’



226
227
228
# File 'lib/parse/datatypes.rb', line 226

def longitude
  @longitude
end

Instance Method Details

#as_json(*a) ⇒ Object



250
251
252
253
254
255
256
# File 'lib/parse/datatypes.rb', line 250

def as_json(*a)
  {
      Protocol::KEY_TYPE => Protocol::TYPE_GEOPOINT,
      "latitude" => @latitude,
      "longitude" => @longitude
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


238
239
240
241
242
# File 'lib/parse/datatypes.rb', line 238

def eql?(other)
  self.class.equal?(other.class) &&
    longitude == other.longitude &&
    latitude == other.latitude
end

#hashObject



246
247
248
# File 'lib/parse/datatypes.rb', line 246

def hash
  longitude.hash ^ latitude.hash
end

#to_json(*a) ⇒ Object



258
259
260
# File 'lib/parse/datatypes.rb', line 258

def to_json(*a)
    as_json.to_json(*a)
end