Class: Fit4Ruby::Lap
- Inherits:
-
FitDataRecord
- Object
- FitDataRecord
- Fit4Ruby::Lap
- Includes:
- FDR_DevField_Extension, RecordAggregator
- Defined in:
- lib/fit4ruby/Lap.rb
Constant Summary
Constants inherited from FitDataRecord
Constants included from BDFieldNameTranslator
BDFieldNameTranslator::BD_DICT
Instance Attribute Summary collapse
-
#lengths ⇒ Object
readonly
Returns the value of attribute lengths.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Attributes inherited from FitDataRecord
Instance Method Summary collapse
-
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
- #check(index, activity) ⇒ Object
-
#initialize(top_level_record, records, previous_lap, field_values, first_length_index, lengths) ⇒ Lap
constructor
Create a new Lap object.
Methods included from FDR_DevField_Extension
#create_dev_field_instance_variables, #each_developer_field, #export, #get_unit_by_name
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
#<=>, #==, #export, #get, #get_as, #get_unit_by_name, #set, #set_field_values, #write
Methods included from BDFieldNameTranslator
Methods included from Converters
#conversion_factor, #fit_time_to_time, #secsToDHMS, #secsToHM, #secsToHMS, #speedToPace, #time_to_fit_time
Constructor Details
#initialize(top_level_record, records, previous_lap, field_values, first_length_index, lengths) ⇒ Lap
Create a new Lap object.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fit4ruby/Lap.rb', line 35 def initialize(top_level_record, records, previous_lap, field_values, first_length_index, lengths) super('lap') @top_level_record = top_level_record @lengths = lengths @meta_field_units['avg_stride_length'] = 'm' @records = records @previous_lap = previous_lap @lengths.each { |length| @records += length.records } @first_length_index = first_length_index @num_lengths = @lengths.length 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 # Create instance variables for developer fields create_dev_field_instance_variables set_field_values(field_values) end |
Instance Attribute Details
#lengths ⇒ Object (readonly)
Returns the value of attribute lengths.
24 25 26 |
# File 'lib/fit4ruby/Lap.rb', line 24 def lengths @lengths end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
24 25 26 |
# File 'lib/fit4ruby/Lap.rb', line 24 def records @records end |
Instance Method Details
#avg_stride_length ⇒ Object
Compute the average stride length for this Session.
88 89 90 91 92 |
# File 'lib/fit4ruby/Lap.rb', line 88 def avg_stride_length return nil unless @total_distance && @total_strides @total_distance / (@total_strides * 2.0) end |
#check(index, activity) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fit4ruby/Lap.rb', line 66 def check(index, activity) unless @message_index == index Log.fatal "message_index must be #{index}, not #{@message_index}" end return if @num_lengths.zero? unless @first_length_index Log.fatal 'first_length_index is not set' end @first_length_index.upto(@first_length_index - @num_lengths) do |i| if (length = activity.lengths[i]) @lengths << length else Log.fatal "Lap references length #{i} which is not contained in " "the FIT file." end end end |