Class: TrackAndDistance
- Inherits:
-
Object
- Object
- TrackAndDistance
- Defined in:
- lib/track_and_distance.rb
Overview
Holds a bearing and distance
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(bearing, distance, radians = false) ⇒ TrackAndDistance
constructor
A new instance of TrackAndDistance.
-
#to_ary ⇒ Array
(also: #deconstruct)
With members bearing and distance.
-
#to_hash ⇒ Hash
(also: #deconstruct_keys)
With keys :bearing and :distance.
-
#to_s(fmt = nil) ⇒ String
format string fmt is currently just for the bearing angle.
Constructor Details
#initialize(bearing, distance, radians = false) ⇒ TrackAndDistance
Returns a new instance of TrackAndDistance.
13 14 15 16 |
# File 'lib/track_and_distance.rb', line 13 def initialize(bearing, distance, radians = false) @bearing = Angle.new(bearing, radians) @distance = distance end |
Instance Attribute Details
#distance ⇒ Float
8 9 10 |
# File 'lib/track_and_distance.rb', line 8 def distance @distance end |
Instance Method Details
#to_ary ⇒ Array Also known as: deconstruct
Returns with members bearing and distance.
32 33 34 |
# File 'lib/track_and_distance.rb', line 32 def to_ary return [ @bearing, @distance ] end |
#to_hash ⇒ Hash Also known as: deconstruct_keys
Returns with keys :bearing and :distance.
37 38 39 |
# File 'lib/track_and_distance.rb', line 37 def to_hash return { bearing: @bearing, distance: @distance } end |
#to_s(fmt = nil) ⇒ String
format string fmt is currently just for the bearing angle. Need to change this to include the distance is single format string.
22 23 24 25 26 27 28 29 |
# File 'lib/track_and_distance.rb', line 22 def to_s(fmt = nil) if fmt # needs work to include distance as well as angle fmt. return "#{@bearing.strf(fmt)} #{distance.round(4)}m" else return "#{@bearing.strf} #{distance.round(4)}m" end end |