Class: Fit4Ruby::DeviceInfo
- Inherits:
-
FitDataRecord
- Object
- FitDataRecord
- Fit4Ruby::DeviceInfo
- Defined in:
- lib/fit4ruby/DeviceInfo.rb
Constant Summary
Constants inherited from FitDataRecord
Constants included from BDFieldNameTranslator
BDFieldNameTranslator::BD_DICT
Instance Attribute Summary
Attributes inherited from FitDataRecord
Instance Method Summary collapse
-
#<=>(fdr) ⇒ Object
Ensure that FitDataRecords have a deterministic sequence.
- #check(index) ⇒ Object
-
#initialize(field_values = {}) ⇒ DeviceInfo
constructor
A new instance of DeviceInfo.
- #numeric_manufacturer ⇒ Object
- #numeric_product ⇒ Object
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(field_values = {}) ⇒ DeviceInfo
Returns a new instance of DeviceInfo.
19 20 21 22 |
# File 'lib/fit4ruby/DeviceInfo.rb', line 19 def initialize(field_values = {}) super('device_info') set_field_values(field_values) end |
Instance Method Details
#<=>(fdr) ⇒ Object
Ensure that FitDataRecords have a deterministic sequence. Device infos are sorted by device_index.
26 27 28 29 30 31 32 33 |
# File 'lib/fit4ruby/DeviceInfo.rb', line 26 def <=>(fdr) @timestamp == fdr. ? @message.name == fdr..name ? @device_index <=> fdr.device_index : RecordOrder.index(@message.name) <=> RecordOrder.index(fdr..name) : @timestamp <=> fdr. end |
#check(index) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fit4ruby/DeviceInfo.rb', line 72 def check(index) unless @device_index Log.fatal 'device info record must have a device_index' end if @device_index == 0 unless @manufacturer Log.fatal 'device info record 0 must have a manufacturer field set' end if @manufacturer == 'garmin' unless @garmin_product Log.fatal 'device info record 0 must have a garman_product ' + 'field set' end else unless @product Log.fatal 'device info record 0 must have a product field set' end end if @serial_number.nil? Log.fatal 'device info record 0 must have a serial number set' end end end |
#numeric_manufacturer ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fit4ruby/DeviceInfo.rb', line 35 def numeric_manufacturer if @manufacturer && @manufacturer.is_a?(String) if @manufacturer[0..17] == 'Undocumented value' return @manufacturer[18..-1].to_i else return GlobalFitDictionaries['manufacturer']. value_by_name(@manufacturer) end end Log.fatal "Unexpected @manufacturer (#{@manufacturer}) value" end |
#numeric_product ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fit4ruby/DeviceInfo.rb', line 48 def numeric_product # The numeric product ID must be an integer or nil. In case the # dictionary did not contain an entry for the numeric ID in the fit file # the @garmin_product or @product variables contain a String starting # with 'Undocumented value ' followed by the ID. if @garmin_product && @garmin_product.is_a?(String) if @garmin_product[0..17] == 'Undocumented value' return @garmin_product[18..-1].to_i else return GlobalFitDictionaries['garmin_product']. value_by_name(@garmin_product) end elsif @product && @product.is_a?(String) if @product[0..17] == 'Undocumented value' return @product[18..-1].to_i else return GlobalFitDictionaries['product'].value_by_name(@product) end end Log.fatal "Unexpected @product (#{@product}) or " + "@garmin_product (#{@garmin_product}) values" end |