Class: Coordinate
- Inherits:
-
Object
- Object
- Coordinate
- Defined in:
- lib/coordinate.rb
Overview
Holds the latitude, longitude, and the altitude for the coordinate
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(latitude = 0, longitude = 0, altitude = 0, radians = false) ⇒ Coordinate
constructor
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).
-
#to_ary ⇒ Latitude, ...
(also: #to_a, #deconstruct)
With members, latitude, longitude and altitude.
-
#to_hash ⇒ Hash
(also: #deconstruct_keys)
With keys :latitude, :longitude, and :altitude.
-
#to_s ⇒ String
Latitude longitude and altitude as a single space separated string.
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
Instance Method Details
#to_ary ⇒ Latitude, ... Also known as: to_a, deconstruct
Returns with members, latitude, longitude and altitude.
26 27 28 |
# File 'lib/coordinate.rb', line 26 def to_ary [ @latitude, @longitude, @altitude ] end |
#to_hash ⇒ Hash Also known as: deconstruct_keys
Returns 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_s ⇒ String
Returns 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 |