Class: RASN1::Types::Enumerated
- Defined in:
- lib/rasn1/types/enumerated.rb
Overview
ASN.1 Enumerated
An enumerated type permits to assign names to integer values. It may be defined different ways:
enum = RASN1::Types::Enumerated.new(enum: { 'a' => 0, 'b' => 1, 'c' => 2 })
enum = RASN1::Types::Enumerated.new(enum: { a: 0, b: 1, c: 2 })
Its value should be setting as an Integer or a String/symbol:
enum.value = :b
enum.value = 1 # equivalent to :b
But its value is always stored as named integer:
enum.value = :b
enum.value # => :b
enum.value = 0
enum.value # => :a
A EnumeratedError is raised when set value is not in enumeration.
Constant Summary collapse
- ID =
Enumerated id value
0x0a
Constants inherited from Primitive
Constants inherited from Base
Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MULTI_OCTETS_ID
Instance Attribute Summary collapse
Attributes inherited from Base
#asn1_class, #default, #name, #options
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Enumerated
constructor
A new instance of Enumerated.
- #to_h ⇒ Hash
Methods inherited from Integer
Methods inherited from Base
#==, #can_build?, constrained?, #constructed?, #do_parse_explicit_with_tracing, #do_parse_with_tracing, encoded_type, #explicit?, #id, #implicit?, #initialize_copy, #inspect, #optional?, parse, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, type, #type, #value, #value=, #value?, #value_size, #void_value
Constructor Details
#initialize(options = {}) ⇒ Enumerated
Returns a new instance of Enumerated.
33 34 35 36 |
# File 'lib/rasn1/types/enumerated.rb', line 33 def initialize(={}) super raise EnumeratedError, 'no enumeration given' if @enum.empty? end |
Instance Attribute Details
#enum ⇒ Hash
|
# File 'lib/rasn1/types/enumerated.rb', line 22
|
Instance Method Details
#to_h ⇒ Hash
39 40 41 |
# File 'lib/rasn1/types/enumerated.rb', line 39 def to_h @enum end |