Class: Fit::File::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/fit/file/record.rb

Constant Summary collapse

@@definitions =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



16
17
18
# File 'lib/fit/file/record.rb', line 16

def content
  @content
end

#headerObject (readonly)

Returns the value of attribute header.



16
17
18
# File 'lib/fit/file/record.rb', line 16

def header
  @header
end

Class Method Details

.clear_definitions!Object



12
13
14
# File 'lib/fit/file/record.rb', line 12

def self.clear_definitions!
  @@definitions.clear
end

.read(io) ⇒ Object



8
9
10
# File 'lib/fit/file/record.rb', line 8

def self.read(io)
  new.read(io)
end

Instance Method Details

#read(io) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fit/file/record.rb', line 18

def read(io)
  @header = RecordHeader.read(io)

  @content = case @header.message_type.snapshot
  when 1
    Definition.read(io).tap do |definition|
      @@definitions[@header.local_message_type.snapshot] = Data.generate(definition)
    end
  when 0
    definition = @@definitions[@header.local_message_type.snapshot]
    # raise "No definition for local message type: #{@header} in #{@@definitions}" if definition.nil?
    definition.read(io) unless definition.nil?
  end

  self
end