Class: Waypoint
- Inherits:
-
Object
- Object
- Waypoint
- Includes:
- BinData, DateTimeParser
- Defined in:
- lib/waypoint.rb
Instance Attribute Summary collapse
-
#altitude ⇒ Object
readonly
Returns the value of attribute altitude.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#heart_rate ⇒ Object
readonly
Returns the value of attribute heart_rate.
-
#position ⇒ Object
Returns the value of attribute position.
-
#segment ⇒ Object
readonly
Returns the value of attribute segment.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #distance_to(other) ⇒ Object
-
#initialize(segment, data = nil) ⇒ Waypoint
constructor
A new instance of Waypoint.
- #last_time ⇒ Object
- #read_data(data) ⇒ Object
- #route ⇒ Object
Methods included from DateTimeParser
Constructor Details
#initialize(segment, data = nil) ⇒ Waypoint
Returns a new instance of Waypoint.
8 9 10 11 12 |
# File 'lib/waypoint.rb', line 8 def initialize(segment, data = nil) @segment = segment @distance = 0 read_data(data) if data end |
Instance Attribute Details
#altitude ⇒ Object (readonly)
Returns the value of attribute altitude.
5 6 7 |
# File 'lib/waypoint.rb', line 5 def altitude @altitude end |
#distance ⇒ Object
Returns the value of attribute distance.
6 7 8 |
# File 'lib/waypoint.rb', line 6 def distance @distance end |
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
6 7 8 |
# File 'lib/waypoint.rb', line 6 def elapsed_time @elapsed_time end |
#heart_rate ⇒ Object (readonly)
Returns the value of attribute heart_rate.
5 6 7 |
# File 'lib/waypoint.rb', line 5 def heart_rate @heart_rate end |
#position ⇒ Object
Returns the value of attribute position.
6 7 8 |
# File 'lib/waypoint.rb', line 6 def position @position end |
#segment ⇒ Object (readonly)
Returns the value of attribute segment.
5 6 7 |
# File 'lib/waypoint.rb', line 5 def segment @segment end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/waypoint.rb', line 5 def time @time end |
Instance Method Details
#distance_to(other) ⇒ Object
55 56 57 |
# File 'lib/waypoint.rb', line 55 def distance_to(other) position.distance_to(other.position) end |
#last_time ⇒ Object
47 48 49 |
# File 'lib/waypoint.rb', line 47 def last_time segment.last_time end |
#read_data(data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/waypoint.rb', line 14 def read_data(data) if route.has_attribute?(:position) LOGGER.debug "route did have the position attribute" @position = LongLat.from_data(data) LOGGER.debug "waypoint position: #{@position.inspect}" end if route.has_attribute?(:time) LOGGER.debug "route did have the time attribute" time_type = BinData::Uint8le.read(data) if time_type == 0 time = read_date_time(data) else time = last_time + BinData::Uint16le.read(data) / 1000 end LOGGER.debug "time was #{Time.at(time)}" @time = time end if route.has_attribute?(:heart_rate) LOGGER.debug "route did have the heart rate attribute" @heartrate = Uint8be.read(data) end if route.has_attribute?(:altitude) LOGGER.debug "route did have the altitude attribute" @altitude = Uint16le.read(data) LOGGER.debug "altitude was #{@altitude}" end data.seek(route.extra_waypoints_attributes_length, ::IO::SEEK_CUR) end |
#route ⇒ Object
51 52 53 |
# File 'lib/waypoint.rb', line 51 def route segment.route end |