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
- TAG =
Enumerated tag value
0x0a
Constants inherited from Primitive
Constants inherited from Base
Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MAX_TAG, Base::UNDUPPABLE_TYPES
Instance Attribute Summary collapse
Attributes inherited from Base
#asn1_class, #default, #name, #value
Instance Method Summary collapse
-
#initialize(value_or_options = {}, options = {}) ⇒ Enumerated
constructor
A new instance of Enumerated.
- #to_h ⇒ Hash
Methods inherited from Integer
Methods inherited from Base
#==, #constructed?, encode_type, #explicit?, #implicit?, #initialize_copy, #inspect, #optional?, parse, #parse!, #primitive?, #tag, #tagged?, #to_der, #type, type, #value_size
Constructor Details
#initialize(options = {}) ⇒ Enumerated #initialize(value, options = {}) ⇒ Enumerated
Returns a new instance of Enumerated.
40 41 42 43 |
# File 'lib/rasn1/types/enumerated.rb', line 40 def initialize(={}, ={}) super raise EnumeratedError, 'no enumeration given' if @enum.nil? end |
Instance Attribute Details
#enum ⇒ Hash
|
# File 'lib/rasn1/types/enumerated.rb', line 22
|
Instance Method Details
#to_h ⇒ Hash
46 47 48 |
# File 'lib/rasn1/types/enumerated.rb', line 46 def to_h @enum end |