Module: Fit4Ruby::FitDefinitionFieldBase
- Included in:
- FitDefinitionField, FitDeveloperDataFieldDefinition
- Defined in:
- lib/fit4ruby/FitDefinitionFieldBase.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_type_bytes ⇒ Object
- #is_array? ⇒ Boolean
- #set_length(count) ⇒ Object
- #set_type(fit_type) ⇒ Object
- #total_bytes ⇒ Object
- #type(fit_type = false) ⇒ Object
- #undefined_value ⇒ Object
Class Method Details
.fit_type_to_bin_data(fit_type) ⇒ Object
19 20 21 22 23 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 19 def FitDefinitionFieldBase::fit_type_to_bin_data(fit_type) entry = FIT_TYPE_DEFS.find { |e| e[0] == fit_type } raise "Unknown fit type #{fit_type}" unless entry entry[1] end |
.undefined_value(fit_type) ⇒ Object
25 26 27 28 29 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 25 def FitDefinitionFieldBase::undefined_value(fit_type) entry = FIT_TYPE_DEFS.find { |e| e[0] == fit_type } raise "Unknown fit type #{fit_type}" unless entry entry[2] end |
Instance Method Details
#base_type_bytes ⇒ Object
68 69 70 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 68 def base_type_bytes FIT_TYPE_DEFS[checked_base_type_number][3] end |
#is_array? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 50 def is_array? if total_bytes > base_type_bytes if total_bytes % base_type_bytes != 0 raise RuntimeError, "Total bytes (#{total_bytes}) must be multiple of " + "base type bytes (#{base_type_bytes}) of type " + "#{base_type_number.snapshot} in Global FIT " + "Message #{name}." end return true end false end |
#set_length(count) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 42 def set_length(count) if (byte_count = FIT_TYPE_DEFS[self.base_type_number][3] * count) > 255 raise ArgumentError, "FitDefinitionField byte count too large (#{byte_count})" end self.byte_count = byte_count end |
#set_type(fit_type) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 31 def set_type(fit_type) idx = FIT_TYPE_DEFS.index { |x| x[0] == fit_type } raise ArgumentError, "Unknown type #{fit_type}" unless idx self.base_type_number = idx self.byte_count = FIT_TYPE_DEFS[idx][3] end |
#total_bytes ⇒ Object
64 65 66 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 64 def total_bytes self.byte_count.snapshot end |
#type(fit_type = false) ⇒ Object
38 39 40 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 38 def type(fit_type = false) FIT_TYPE_DEFS[checked_base_type_number][fit_type ? 0 : 1] end |
#undefined_value ⇒ Object
72 73 74 |
# File 'lib/fit4ruby/FitDefinitionFieldBase.rb', line 72 def undefined_value FIT_TYPE_DEFS[checked_base_type_number][2] end |