Class: Fit4Ruby::Lap
- Inherits:
-
FitDataRecord
- Object
- FitDataRecord
- Fit4Ruby::Lap
- Includes:
- RecordAggregator
- Defined in:
- lib/fit4ruby/Lap.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
- #check ⇒ Object
-
#initialize(records, previous_lap, field_values) ⇒ Lap
constructor
A new instance of Lap.
Methods included from RecordAggregator
#aggregate, #aggregate_ascent_descent, #aggregate_geo_region, #aggregate_heart_rate, #aggregate_speed_distance, #aggregate_stance_time, #aggregate_strides, #aggregate_vertical_oscillation
Methods inherited from FitDataRecord
#<=>, #==, #get, #get_as, #inspect, #set, #set_field_values, #write
Methods included from Converters
#conversion_factor, #fit_time_to_time, #secsToDHMS, #secsToHMS, #speedToPace, #time_to_fit_time
Constructor Details
#initialize(records, previous_lap, field_values) ⇒ Lap
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fit4ruby/Lap.rb', line 24 def initialize(records, previous_lap, field_values) super('lap') ['avg_stride_length'] = 'm' @records = records @previous_lap = previous_lap if previous_lap && previous_lap.records && previous_lap.records.last # Set the start time of the new lap to the timestamp of the last record # of the previous lap. @start_time = previous_lap.records.last. elsif records.first # Or to the timestamp of the first record. @start_time = records.first. end if records.last @total_elapsed_time = records.last. - @start_time end set_field_values(field_values) end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
22 23 24 |
# File 'lib/fit4ruby/Lap.rb', line 22 def records @records end |
Instance Method Details
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
65 66 67 68 69 |
# File 'lib/fit4ruby/Lap.rb', line 65 def avg_stride_length return nil unless @total_distance && @total_strides @total_distance / (@total_strides * 2.0) end |
#check ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fit4ruby/Lap.rb', line 46 def check ts = Time.parse('1989-12-31') distance = nil @records.each do |r| Log.error "Record has no timestamp" unless r. if r. < ts Log.error "Record has earlier timestamp than previous record" end if r.distance if distance && r.distance < distance Log.error "Record has smaller distance than previous record" end distance = r.distance end ts = r. end end |