Class: Fit4Ruby::Lap

Inherits:
FitDataRecord show all
Includes:
RecordAggregator
Defined in:
lib/fit4ruby/Lap.rb

Constant Summary

Constants inherited from FitDataRecord

FitDataRecord::RecordOrder

Instance Attribute Summary collapse

Attributes inherited from FitDataRecord

#message

Instance Method Summary collapse

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, #secsToHM, #secsToHMS, #speedToPace, #time_to_fit_time

Constructor Details

#initialize(records, previous_lap, field_values) ⇒ Lap

Returns a new instance of 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')
  @meta_field_units['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.timestamp
  elsif records.first
    # Or to the timestamp of the first record.
    @start_time = records.first.timestamp
  end

  if records.last
    @total_elapsed_time = records.last.timestamp - @start_time
  end

  set_field_values(field_values)
end

Instance Attribute Details

#recordsObject (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_lengthObject

Compute the average stride length for this Session.



53
54
55
56
57
# File 'lib/fit4ruby/Lap.rb', line 53

def avg_stride_length
  return nil unless @total_distance && @total_strides

  @total_distance / (@total_strides * 2.0)
end

#check(index) ⇒ Object



46
47
48
49
50
# File 'lib/fit4ruby/Lap.rb', line 46

def check(index)
  unless @message_index == index
    Log.fatal "message_index must be #{index}, not #{@message_index}"
  end
end