Module: Fit4Ruby::FDR_DevField_Extension
Overview
This module extends FitDataRecord derived classes in case they have developer fields.
Instance Method Summary collapse
- #create_dev_field_instance_variables ⇒ Object
- #each_developer_field ⇒ Object
- #export ⇒ Object
- #get_unit_by_name(name) ⇒ Object
Instance Method Details
#create_dev_field_instance_variables ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fit4ruby/FDR_DevField_Extension.rb', line 19 def create_dev_field_instance_variables # Create instance variables for developer fields @dev_field_descriptions = {} @top_level_record.field_descriptions.each do |field_description| # Only create instance variables if the FieldDescription is for this # message number. if field_description.native_mesg_num == @message.number name = field_description.full_field_name(@top_level_record. developer_data_ids) create_instance_variable(name) @dev_field_descriptions[name] = field_description end end end |
#each_developer_field ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fit4ruby/FDR_DevField_Extension.rb', line 34 def each_developer_field @top_level_record.field_descriptions.each do |field_description| # Only create instance variables if the FieldDescription is for this # message number. if field_description.native_mesg_num == @message.number name = field_description.full_field_name(@top_level_record. developer_data_ids) yield(field_description, instance_variable_get('@' + name)) end end end |
#export ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fit4ruby/FDR_DevField_Extension.rb', line 54 def export = super each_developer_field do |field_description, ivar| field = field_description..fields_by_number[ field_description.native_field_num] fit_value = field.native_to_fit(ivar) unless field.is_undefined?(fit_value) fld = { 'number' => field_description.native_field_num | 128, 'value' => field.fit_to_native(fit_value), #'human' => field.to_human(fit_value), 'type' => field.type } fld['unit'] = field.opts[:unit] if field.opts[:unit] fld['scale'] = field.opts[:scale] if field.opts[:scale] ['fields'][field.name] = fld end end end |
#get_unit_by_name(name) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/fit4ruby/FDR_DevField_Extension.rb', line 46 def get_unit_by_name(name) if /[A-Za-z_]+_[A-F0-9]{16}/ =~ name @dev_field_descriptions[name].units else super end end |