Module: Fit::File::Definitions

Defined in:
lib/fit/file/definitions.rb

Constant Summary collapse

@@fields =
Hash.new{ |h,k| h[k]= {} }
@@dyn_fields =
Hash.new{ |h,k| h[k]= {} }
@@names =
Hash.new

Class Method Summary collapse

Class Method Details

.add_field(global_msg_num, field_def_num, name, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fit/file/definitions.rb', line 10

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

.add_name(global_msg_num, name) ⇒ Object



35
36
37
# File 'lib/fit/file/definitions.rb', line 35

def add_name(global_msg_num, name)
  @@names[global_msg_num] = name
end

.get_dynamic_fields(global_msg_num, field_def_num) ⇒ Object



31
32
33
# File 'lib/fit/file/definitions.rb', line 31

def get_dynamic_fields(global_msg_num, field_def_num)
  @@dyn_fields[global_msg_num][field_def_num] 
end

.get_field(global_msg_num, field_def_num) ⇒ Object



27
28
29
# File 'lib/fit/file/definitions.rb', line 27

def get_field(global_msg_num, field_def_num)
  @@fields[global_msg_num][field_def_num]
end

.get_name(global_msg_num) ⇒ Object



39
40
41
# File 'lib/fit/file/definitions.rb', line 39

def get_name(global_msg_num)
  @@names[global_msg_num]
end