Class: TimexDatalinkClient::Protocol9::Eeprom::Chrono

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Helpers::CharEncoders
Defined in:
lib/timex_datalink_client/protocol_9/eeprom/chrono.rb

Constant Summary collapse

CHRONO_LABEL_LENGTH =
8
CHRONO_INITIAL_SIZE =
14

Constants included from Helpers::CharEncoders

Helpers::CharEncoders::CHARS, Helpers::CharEncoders::CHARS_PROTOCOL_6, Helpers::CharEncoders::EEPROM_CHARS, Helpers::CharEncoders::EEPROM_TERMINATOR, Helpers::CharEncoders::INVALID_CHAR, Helpers::CharEncoders::PHONE_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CharEncoders

#chars_for, #eeprom_chars_for, #phone_chars_for, #protocol_6_chars_for

Constructor Details

#initialize(label:, laps:) ⇒ Chrono

Create a Chrono instance.

Parameters:

  • label (String)

    Label for chrono.

  • laps (Integer)

    Number of laps for chrono.



29
30
31
32
# File 'lib/timex_datalink_client/protocol_9/eeprom/chrono.rb', line 29

def initialize(label:, laps:)
  @label = label
  @laps = laps
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



17
18
19
# File 'lib/timex_datalink_client/protocol_9/eeprom/chrono.rb', line 17

def label
  @label
end

#lapsObject

Returns the value of attribute laps.



17
18
19
# File 'lib/timex_datalink_client/protocol_9/eeprom/chrono.rb', line 17

def laps
  @laps
end

Instance Method Details

#chrono_bytesizeObject



44
45
46
# File 'lib/timex_datalink_client/protocol_9/eeprom/chrono.rb', line 44

def chrono_bytesize
  CHRONO_INITIAL_SIZE + laps * 4
end

#packetArray<Integer>

Compile a packet for a chrono.

Returns:

  • (Array<Integer>)

    Array of integers that represent bytes.

Raises:

  • (ActiveModel::ValidationError)

    One or more model values are invalid.



38
39
40
41
42
# File 'lib/timex_datalink_client/protocol_9/eeprom/chrono.rb', line 38

def packet
  validate!

  label_characters
end