Class: FitParser::File::Record

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definitions, dev_definitions) ⇒ Record

Returns a new instance of Record.



6
7
8
9
# File 'lib/fit_parser/file/record.rb', line 6

def initialize(definitions, dev_definitions)
  @definitions = definitions
  @dev_definitions = dev_definitions
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/fit_parser/file/record.rb', line 4

def content
  @content
end

#definitionsObject (readonly)

Returns the value of attribute definitions.



4
5
6
# File 'lib/fit_parser/file/record.rb', line 4

def definitions
  @definitions
end

#headerObject (readonly)

Returns the value of attribute header.



4
5
6
# File 'lib/fit_parser/file/record.rb', line 4

def header
  @header
end

Instance Method Details

#read(io) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fit_parser/file/record.rb', line 11

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

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

  self
end