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.



256
257
258
259
260
261
262
263
264
# File 'lib/parse/datatypes.rb', line 256

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}’



254
255
256
# File 'lib/parse/datatypes.rb', line 254

def latitude
  @latitude
end

#longitudeObject

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



254
255
256
# File 'lib/parse/datatypes.rb', line 254

def longitude
  @longitude
end

Instance Method Details

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

Returns:

  • (Boolean)


266
267
268
269
270
# File 'lib/parse/datatypes.rb', line 266

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

#hashObject



274
275
276
# File 'lib/parse/datatypes.rb', line 274

def hash
  longitude.hash ^ latitude.hash
end

#to_h(*a) ⇒ Object Also known as: as_json



278
279
280
281
282
283
284
# File 'lib/parse/datatypes.rb', line 278

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

#to_json(*a) ⇒ Object



287
288
289
# File 'lib/parse/datatypes.rb', line 287

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

#to_sObject



291
292
293
# File 'lib/parse/datatypes.rb', line 291

def to_s
  "(#{latitude}, #{longitude})"
end