Class: Fit::File::Data

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/fit/file/data.rb

Class Method Summary collapse

Class Method Details

.generate(definition) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fit/file/data.rb', line 7

def self.generate(definition)
  type = Definitions.get_name(definition.global_message_number.snapshot) ||
    "data_record_#{definition.global_message_number.snapshot}"

  Class.new(self) do
    self.global_message_number = definition.global_message_number.snapshot

    endian definition.endianness

    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def record_type
        :#{type}
      end
    RUBY

    definition.fields.each do |field|
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        #{field.type} :#{field.raw_name}

        def #{field.name}
          #{field.raw_name}.snapshot #{ "/ #{field.scale.inspect}.0" if field.scale }
        end
      RUBY
    end
  end
end