Class: FitParser::File

Inherits:
Object
  • Object
show all
Defined in:
lib/fit_parser/file.rb,
lib/fit_parser/file/data.rb,
lib/fit_parser/file/type.rb,
lib/fit_parser/file/types.rb,
lib/fit_parser/file/header.rb,
lib/fit_parser/file/record.rb,
lib/fit_parser/file/definition.rb,
lib/fit_parser/file/definitions.rb,
lib/fit_parser/file/record_header.rb

Defined Under Namespace

Modules: Definitions, Types Classes: Data, Definition, Header, Record, RecordHeader, Type

Constant Summary collapse

MSG_NUM_FIELD_DESCRIPTION =
206

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFile

Returns a new instance of File.



11
12
13
# File 'lib/fit_parser/file.rb', line 11

def initialize
  @records = []
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



9
10
11
# File 'lib/fit_parser/file.rb', line 9

def crc
  @crc
end

#headerObject (readonly)

Returns the value of attribute header.



9
10
11
# File 'lib/fit_parser/file.rb', line 9

def header
  @header
end

#recordsObject (readonly)

Returns the value of attribute records.



9
10
11
# File 'lib/fit_parser/file.rb', line 9

def records
  @records
end

Class Method Details

.read(io) ⇒ Object



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

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

Instance Method Details

#read(io) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fit_parser/file.rb', line 15

def read(io)
  @header = Header.read(io)
  definitions = {}
  dev_definitions = {}
  while io.pos < @header.end_pos
    record = Record.new(definitions, dev_definitions)
    @records << record.read(io)
    content = record.content
    if content[:global_message_number] == MSG_NUM_FIELD_DESCRIPTION
      field_definition_local_message_type = record.header.local_message_type
    end
    if !content[:global_message_number] && field_definition_local_message_type && record.header.local_message_type == field_definition_local_message_type
      dev_definitions[content[:raw_field_0].to_s] ||= {}
      dev_definitions[content[:raw_field_0].to_s][content[:raw_field_1].to_s] = content
    end
    definitions = record.definitions
  end
  @crc = io.read(2)
  self
end