Class: Waypoint

Inherits:
Object
  • Object
show all
Includes:
BinData, DateTimeParser
Defined in:
lib/waypoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DateTimeParser

#read_date_time

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

#altitudeObject (readonly)

Returns the value of attribute altitude.



5
6
7
# File 'lib/waypoint.rb', line 5

def altitude
  @altitude
end

#distanceObject

Returns the value of attribute distance.



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

def distance
  @distance
end

#elapsed_timeObject

Returns the value of attribute elapsed_time.



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

def elapsed_time
  @elapsed_time
end

#heart_rateObject (readonly)

Returns the value of attribute heart_rate.



5
6
7
# File 'lib/waypoint.rb', line 5

def heart_rate
  @heart_rate
end

#positionObject

Returns the value of attribute position.



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

def position
  @position
end

#segmentObject (readonly)

Returns the value of attribute segment.



5
6
7
# File 'lib/waypoint.rb', line 5

def segment
  @segment
end

#timeObject (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_timeObject



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

#routeObject



51
52
53
# File 'lib/waypoint.rb', line 51

def route
  segment.route
end