Class: Route
- Inherits:
-
Object
- Object
- Route
- Defined in:
- lib/route.rb
Constant Summary collapse
- WAYPOINT_ATTRIBUTES =
{ :position => 1, :time => 2, :heart_rate => 4, :altitude => 8 }
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#elapsed_time ⇒ Object
readonly
Returns the value of attribute elapsed_time.
-
#extra_waypoints_attributes_length ⇒ Object
readonly
Returns the value of attribute extra_waypoints_attributes_length.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
- #add_distance(dist) ⇒ Object
- #add_elapsed_time(time) ⇒ Object
- #calculate_parameters ⇒ Object
- #distance_from_parameterized_location(location) ⇒ Object
- #has_attribute?(attribute) ⇒ Boolean
-
#initialize ⇒ Route
constructor
A new instance of Route.
- #parameterized_location_from_time(time) ⇒ Object
- #position_from_parameterized_location(location) ⇒ Object
- #read_data(data) ⇒ Object
- #waypoints_and_parameter_from_parameterized_location(location) ⇒ Object
Constructor Details
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/route.rb', line 9 def attributes @attributes end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
9 10 11 |
# File 'lib/route.rb', line 9 def distance @distance end |
#elapsed_time ⇒ Object (readonly)
Returns the value of attribute elapsed_time.
9 10 11 |
# File 'lib/route.rb', line 9 def elapsed_time @elapsed_time end |
#extra_waypoints_attributes_length ⇒ Object (readonly)
Returns the value of attribute extra_waypoints_attributes_length.
9 10 11 |
# File 'lib/route.rb', line 9 def extra_waypoints_attributes_length @extra_waypoints_attributes_length end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
9 10 11 |
# File 'lib/route.rb', line 9 def segments @segments end |
Class Method Details
.from_data(data) ⇒ Object
12 13 14 |
# File 'lib/route.rb', line 12 def self.from_data(data) new.read_data(data) end |
Instance Method Details
#add_distance(dist) ⇒ Object
77 78 79 |
# File 'lib/route.rb', line 77 def add_distance(dist) @distance += dist end |
#add_elapsed_time(time) ⇒ Object
81 82 83 |
# File 'lib/route.rb', line 81 def add_elapsed_time(time) @elapsed_time += time end |
#calculate_parameters ⇒ Object
34 35 36 |
# File 'lib/route.rb', line 34 def calculate_parameters segments.each{|s| s.calculate_waypoints} end |
#distance_from_parameterized_location(location) ⇒ Object
53 54 55 56 57 |
# File 'lib/route.rb', line 53 def distance_from_parameterized_location(location) return unless location w0, w1, t = waypoints_and_parameter_from_parameterized_location(location) w0.distance + t * (w1.distance - w0.distance) end |
#has_attribute?(attribute) ⇒ Boolean
30 31 32 |
# File 'lib/route.rb', line 30 def has_attribute?(attribute) 0 != (attributes & WAYPOINT_ATTRIBUTES[attribute]) end |
#parameterized_location_from_time(time) ⇒ Object
38 39 40 41 |
# File 'lib/route.rb', line 38 def parameterized_location_from_time(time) return unless segment = segment_for_time(time) segment.parameterized_location_from_time(time) end |
#position_from_parameterized_location(location) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/route.rb', line 43 def position_from_parameterized_location(location) return unless location w0, w1, t = waypoints_and_parameter_from_parameterized_location(location) LongLat.new( w0.position.longitude + t * (w1.position.longitude - w0.position.longitude), w0.position.latitude + t * (w1.position.latitude - w0.position.latitude) ) end |
#read_data(data) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/route.rb', line 23 def read_data(data) @attributes = BinData::Uint16le.read(data) @extra_waypoints_attributes_length = BinData::Uint16be.read(data) read_segments_from(data) self end |
#waypoints_and_parameter_from_parameterized_location(location) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/route.rb', line 59 def waypoints_and_parameter_from_parameterized_location(location) return unless location && segment = segments[location.segment_index] waypoints = segment.waypoints value = location.value.to_i if value >= waypoints.size - 1 value = waypoints.size - 2 end t = location.value - value waypoints.size < 2 ? [waypoints[0], waypoints[0], 0] : [waypoints[value], waypoints[value + 1], t] end |