Class: Flic::Protocol::Primitives::Enum
- Inherits:
-
BinData::Primitive
- Object
- BinData::Primitive
- Flic::Protocol::Primitives::Enum
- Defined in:
- lib/flic/protocol/primitives/enum.rb
Overview
An abstract class for 1 byte enums
Direct Known Subclasses
BluetoothAddressType, BluetoothControllerState, ClickType, ConnectionStatus, CreateConnectionChannelError, DisconnectReason, LatencyMode, RemovedReason, ScanWizardResult
Defined Under Namespace
Classes: Error, InvalidOctetError, InvalidOptionError
Class Method Summary collapse
-
.max_octet ⇒ Integer
The byte value for the option with the largest byte value.
-
.next_available_octet ⇒ Integer
The next available byte value (starting at 0x00).
-
.octet_option ⇒ Hash
A map of byte values to options.
-
.octets ⇒ Array
The valid byte values for this enum.
-
.option_octet ⇒ Hash
A map of options to byte values.
-
.options ⇒ Array
The valid options for this enum.
Instance Method Summary collapse
Class Method Details
.max_octet ⇒ Integer
Returns the byte value for the option with the largest byte value.
36 37 38 |
# File 'lib/flic/protocol/primitives/enum.rb', line 36 def max_octet octets.max end |
.next_available_octet ⇒ Integer
Returns the next available byte value (starting at 0x00).
41 42 43 44 45 46 47 |
# File 'lib/flic/protocol/primitives/enum.rb', line 41 def next_available_octet if max_octet 1 + max_octet else 0 end end |
.octet_option ⇒ Hash
Returns a map of byte values to options.
21 22 23 |
# File 'lib/flic/protocol/primitives/enum.rb', line 21 def octet_option @octet_option ||= {} end |
.octets ⇒ Array
Returns the valid byte values for this enum.
31 32 33 |
# File 'lib/flic/protocol/primitives/enum.rb', line 31 def octets octet_option.keys end |
.option_octet ⇒ Hash
Returns a map of options to byte values.
16 17 18 |
# File 'lib/flic/protocol/primitives/enum.rb', line 16 def option_octet @option_octet ||= {} end |
.options ⇒ Array
Returns the valid options for this enum.
26 27 28 |
# File 'lib/flic/protocol/primitives/enum.rb', line 26 def option_octet.keys end |
Instance Method Details
#get ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/flic/protocol/primitives/enum.rb', line 68 def get if octet_option.has_key?(octet) octet_option[octet] else raise InvalidOctetError, "No such octet `#{octet.inspect}` for enum #{inspect}" end end |
#set(option) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/flic/protocol/primitives/enum.rb', line 76 def set(option) if option_octet.has_key?(option) self.octet = self.class.option_octet[option] else raise InvalidOptionError, "No such option `#{option.inspect}` for enum #{inspect}" end end |