Class: TimexDatalinkClient::Protocol7::Eeprom::PhoneNumber

Inherits:
Object
  • Object
show all
Includes:
Helpers::FourByteFormatter
Defined in:
lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb

Constant Summary collapse

PHONE_NUMBER_DIGITS_MAP =
{
  "0" => 0x001,
  "1" => 0x002,
  "2" => 0x003,
  "3" => 0x004,
  "4" => 0x005,
  "5" => 0x006,
  "6" => 0x007,
  "7" => 0x008,
  "8" => 0x009,
  "9" => 0x00a
}.freeze
PACKETS_TERMINATOR =
0x03

Constants included from Helpers::FourByteFormatter

Helpers::FourByteFormatter::BYTE_NULL, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDF, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FourByteFormatter

#four_byte_format_for

Constructor Details

#initialize(name: [], number:) ⇒ PhoneNumber

Create a PhoneNumber instance.

Parameters:

  • name (Array<Integer>) (defaults to: [])

    Name associated to phone number.

  • number (String)

    Phone number text.



56
57
58
59
# File 'lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb', line 56

def initialize(name: [], number:)
  @name = name
  @number = number
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



49
50
51
# File 'lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb', line 49

def name
  @name
end

#numberObject

Returns the value of attribute number.



49
50
51
# File 'lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb', line 49

def number
  @number
end

Class Method Details

.packets(phone_numbers) ⇒ Array

Compile data for all phone numbers.

Parameters:

  • phone_numbers (Array<PhoneNumber>)

    Phone numbers to compile data for.

Returns:

  • (Array)

    Compiled data of all phone numbers.



30
31
32
# File 'lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb', line 30

def self.packets(phone_numbers)
  header(phone_numbers) + names_and_numbers(phone_numbers) + [PACKETS_TERMINATOR]
end

Instance Method Details

#name_and_numberArray<Integer>

Compile an unformatted name and phone number.

Returns:

  • (Array<Integer>)

    Array of integers that represent bytes.



64
65
66
67
68
69
# File 'lib/timex_datalink_client/protocol_7/eeprom/phone_number.rb', line 64

def name_and_number
  [
    name,
    number_characters
  ]
end