Class: RecordHeader

Inherits:
FitObject show all
Defined in:
lib/fitreader/record_header.rb

Constant Summary

Constants included from Unpack

Unpack::MASKS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FitObject

#to_h

Methods included from Unpack

#read_bit, #read_bits, #read_multiple, #readbytes

Constructor Details

#initialize(io) ⇒ RecordHeader

Returns a new instance of RecordHeader.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fitreader/record_header.rb', line 4

def initialize(io)
  byte = io.readbyte

  @header_type = read_bit(byte, 7)             # 0 = normal, 1 = timestamp
  if @header_type.zero?
    @message_type = read_bit(byte, 6)          # 1 = definition, 0 = data
    @message_type_specific = read_bit(byte, 5) # 1 = developer fields
    @reserved = read_bit(byte, 4)
    @local_message_type = read_bits(byte, 3..0)
  else
    @local_message_type = read_bits(byte, 6..5)
    @time_offset = read_bits(byte, 4..0)
  end
end

Instance Attribute Details

#header_typeObject

Returns the value of attribute header_type.



2
3
4
# File 'lib/fitreader/record_header.rb', line 2

def header_type
  @header_type
end

#local_message_typeObject

Returns the value of attribute local_message_type.



2
3
4
# File 'lib/fitreader/record_header.rb', line 2

def local_message_type
  @local_message_type
end

#message_typeObject

Returns the value of attribute message_type.



2
3
4
# File 'lib/fitreader/record_header.rb', line 2

def message_type
  @message_type
end

#message_type_specificObject

Returns the value of attribute message_type_specific.



2
3
4
# File 'lib/fitreader/record_header.rb', line 2

def message_type_specific
  @message_type_specific
end

#time_offsetObject

Returns the value of attribute time_offset.



2
3
4
# File 'lib/fitreader/record_header.rb', line 2

def time_offset
  @time_offset
end

Instance Method Details

#data?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/fitreader/record_header.rb', line 23

def data?
  @header_type.zero? && @message_type.zero?
end

#definition?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/fitreader/record_header.rb', line 19

def definition?
  @header_type.zero? && @message_type == 1
end

#timestamp?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/fitreader/record_header.rb', line 27

def timestamp?
  @header_type == 1
end