Class: Fit4Ruby::Record

Inherits:
FitDataRecord show all
Includes:
FDR_DevField_Extension
Defined in:
lib/fit4ruby/Record.rb

Overview

The Record corresponds to the record FIT message. A Record is a basic set of primary measurements that are associated with a certain timestamp.

Constant Summary

Constants inherited from FitDataRecord

FitDataRecord::RecordOrder

Constants included from BDFieldNameTranslator

BDFieldNameTranslator::BD_DICT

Constants included from Converters

Converters::FACTORS, Converters::OFFSETS

Instance Attribute Summary

Attributes inherited from FitDataRecord

#message, #timestamp

Instance Method Summary collapse

Methods included from FDR_DevField_Extension

#create_dev_field_instance_variables, #each_developer_field, #export, #get_unit_by_name

Methods inherited from FitDataRecord

#<=>, #==, #export, #get, #get_as, #get_unit_by_name, #set, #set_field_values, #write

Methods included from BDFieldNameTranslator

#to_bd_field_name

Methods included from Converters

#conversion_factor, #conversion_offset, #fit_time_to_time, #secsToDHMS, #secsToHM, #secsToHMS, #speedToPace, #time_to_fit_time

Constructor Details

#initialize(top_level_record, field_values = {}) ⇒ Record

Create a new Record object.

Parameters:

  • fit_entity

    The FitEntity this record belongs to

  • field_values (Hash) (defaults to: {})

    Hash that provides initial values for certain fields.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fit4ruby/Record.rb', line 28

def initialize(top_level_record, field_values = {})
  super('record')
  @top_level_record = top_level_record
  @meta_field_units['pace'] = 'min/km'
  @meta_field_units['run_cadence'] = 'spm'

  # Create instance variables for developer fields
  create_dev_field_instance_variables

  set_field_values(field_values)
end

Instance Method Details

#paceFloat or nil

Convert the ‘speed’ or ‘enhanced_speed’ field into a running pace. The pace is measured in minutes per Kilometer.

Returns:

  • (Float or nil)

    pace for this Record in m/s or nil if not available.



54
55
56
57
58
# File 'lib/fit4ruby/Record.rb', line 54

def pace
  return nil unless @speed || @enhanced_speed

  1000.0 / ((@speed || @enhanced_speed) * 60.0)
end

#run_cadenceObject



40
41
42
43
44
45
46
47
48
# File 'lib/fit4ruby/Record.rb', line 40

def run_cadence
  if @cadence && @fractional_cadence
    (@cadence + @fractional_cadence) * 2
  elsif @cadence
    @cadence * 2
  else
    nil
  end
end