Class: Coordinate

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

Overview

Holds the latitude, longitude, and the altitude for the coordinate

Direct Known Subclasses

Vincenty

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude = 0, longitude = 0, altitude = 0, radians = false) ⇒ Coordinate

latitude and longitude can be Strings or Numeric, or anything else with to_radians and to_f latitude and longitude are in degrees unless radians == true (or set to :radians)



14
15
16
17
18
# File 'lib/coordinate.rb', line 14

def initialize(latitude = 0, longitude = 0, altitude = 0, radians = false)
  @latitude = Latitude.new(latitude, radians)
  @longitude = Longitude.new(longitude, radians)
  @altitude = altitude.to_f
end

Instance Attribute Details

#altitudeNumeric

Returns:



10
11
12
# File 'lib/coordinate.rb', line 10

def altitude
  @altitude
end

#latitudeLatitude

Returns:



6
7
8
# File 'lib/coordinate.rb', line 6

def latitude
  @latitude
end

#longitudeLongitude

Returns:



8
9
10
# File 'lib/coordinate.rb', line 8

def longitude
  @longitude
end

Instance Method Details

#to_aryLatitude, ... Also known as: to_a, deconstruct

Returns with members, latitude, longitude and altitude.

Returns:



26
27
28
# File 'lib/coordinate.rb', line 26

def to_ary
  [ @latitude, @longitude, @altitude ]
end

#to_hashHash Also known as: deconstruct_keys

Returns with keys :latitude, :longitude, and :altitude.

Returns:

  • (Hash)

    with keys :latitude, :longitude, and :altitude



33
34
35
# File 'lib/coordinate.rb', line 33

def to_hash
  { latitude: @latitude, longitude: @longitude, altitude: @altitude }
end

#to_sString

Returns Latitude longitude and altitude as a single space separated string.

Returns:

  • (String)

    Latitude longitude and altitude as a single space separated string.



21
22
23
# File 'lib/coordinate.rb', line 21

def to_s
  "#{@latitude}  #{@longitude} #{@altitude}m"
end