lib/fit_parser/file/definitions.rb in fit_parser-0.0.4 vs lib/fit_parser/file/definitions.rb in fit_parser-0.0.5
- old
+ new
@@ -1,48 +1,64 @@
module FitParser
class File
module Definitions
+ def self.fields
+ @fields ||= Hash.new { |h, k| h[k]= {} }
+ end
- @@fields = Hash.new{ |h,k| h[k]= {} }
- @@dyn_fields = Hash.new{ |h,k| h[k]= {} }
- @@names = Hash.new
+ def self.fields=(value)
+ @fields = value
+ end
- class << self
- def add_field(global_msg_num, field_def_num, name, options = {})
- if @@fields[global_msg_num].has_key? field_def_num
- raise "bad definition of dynamic field (#{name}) without :ref_field_name or :ref_field_values" unless options.has_key?(:ref_field_name) && options.has_key?(:ref_field_values)
- @@dyn_fields[global_msg_num][field_def_num] ||= {}
- @@dyn_fields[global_msg_num][field_def_num][name.to_sym] = options
- # let's put the ref_field_values with the raw_value instead of the real value
- type = Types.get_type_definition(options[:ref_field_name].to_sym) if options[:ref_field_name]
- # basic types are not found and returns nil (also some rspec dummy tests)
- if type
- type = type[:values].invert
- @@dyn_fields[global_msg_num][field_def_num][name.to_sym][:ref_field_values] = options[:ref_field_values].map { |elt| type[elt.to_s] }
- end
- else
- @@fields[global_msg_num][field_def_num] = options.merge(:name => name)
- end
- end
+ def self.dyn_fields
+ @dyn_fields ||= Hash.new { |h, k| h[k]= {} }
+ end
- def get_field(global_msg_num, field_def_num)
- @@fields[global_msg_num][field_def_num]
- end
+ def self.dyn_fields=(value)
+ @dyn_fields = value
+ end
- def get_dynamic_fields(global_msg_num, field_def_num)
- @@dyn_fields[global_msg_num][field_def_num]
- end
+ def self.names
+ @names ||= Hash.new
+ end
- def add_name(global_msg_num, name)
- @@names[global_msg_num] = name
- end
+ def self.names=(value)
+ @names = value
+ end
- def get_name(global_msg_num)
- @@names[global_msg_num]
+ def self.add_field(global_msg_num, field_def_num, name, options = {})
+ if Definitions.fields[global_msg_num].has_key? field_def_num
+ raise "bad definition of dynamic field (#{name}) without :ref_field_name or :ref_field_values" unless options.has_key?(:ref_field_name) && options.has_key?(:ref_field_values)
+ Definitions.dyn_fields[global_msg_num][field_def_num] ||= {}
+ Definitions.dyn_fields[global_msg_num][field_def_num][name.to_sym] = options
+ # let's put the ref_field_values with the raw_value instead of the real value
+ type = Types.get_type_definition(options[:ref_field_name].to_sym) if options[:ref_field_name]
+ # basic types are not found and returns nil (also some rspec dummy tests)
+ if type
+ type = type[:values].invert
+ Definitions.dyn_fields[global_msg_num][field_def_num][name.to_sym][:ref_field_values] = options[:ref_field_values].map { |elt| type[elt.to_s] }
+ end
+ else
+ Definitions.fields[global_msg_num][field_def_num] = options.merge(:name => name)
end
end
+ def self.get_field(global_msg_num, field_def_num)
+ Definitions.fields[global_msg_num][field_def_num]
+ end
+
+ def self.get_dynamic_fields(global_msg_num, field_def_num)
+ Definitions.dyn_fields[global_msg_num][field_def_num]
+ end
+
+ def self.add_name(global_msg_num, name)
+ Definitions.names[global_msg_num] = name
+ end
+
+ def self.get_name(global_msg_num)
+ Definitions.names[global_msg_num]
+ end
end
end
end
# DATA
@@ -680,10 +696,10 @@
FitParser::File::Definitions.add_field 55, 4, 'active_time', :type => :uint32, :scale => 1000, :unit => 's'
FitParser::File::Definitions.add_field 55, 5, 'activity_type', :type => :activity_type
FitParser::File::Definitions.add_field 55, 6, 'activity_subtype', :type => :activity_subtype
FitParser::File::Definitions.add_field 55, 7, 'activity_level', :type => :activity_level
FitParser::File::Definitions.add_field 55, 8, 'distance_16', :type => :uint16, :unit => '100 * m'
-FitParser::File::Definitions.add_field 55, 9, 'cycles_16', :type => :uint16, :unit => '2 * cycles ', :unit => '(steps)'
+FitParser::File::Definitions.add_field 55, 9, 'cycles_16', :type => :uint16, :unit => '(steps)'
FitParser::File::Definitions.add_field 55, 10, 'active_time_16', :type => :uint16, :unit => 's'
FitParser::File::Definitions.add_field 55, 11, 'local_timestamp', :type => :local_date_time
FitParser::File::Definitions.add_field 55, 12, 'temperature', :type => :sint16, :scale => 100, :unit => 'C'
FitParser::File::Definitions.add_field 55, 14, 'temperature_min', :type => :sint16, :scale => 100, :unit => 'C'
FitParser::File::Definitions.add_field 55, 15, 'temperature_max', :type => :sint16, :scale => 100, :unit => 'C'