Class: OSPFv2::OpaqueType

Inherits:
Object show all
Includes:
IE
Defined in:
lib/ie/opaque_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IE

#method_missing

Constructor Details

#initialize(opaque_type = 1) ⇒ OpaqueType

Returns a new instance of OpaqueType.



50
51
52
53
54
55
56
57
58
59
# File 'lib/ie/opaque_type.rb', line 50

def initialize(opaque_type=1)
  @opaque_type = case opaque_type
  when Symbol
    OpaqueType.to_i(opaque_type)
  when Fixnum
    opaque_type
  else
    raise ArgumentError, "Invalid OpaqueType #{opaque_type}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OSPFv2::IE

Class Method Details

.allObject



26
27
28
# File 'lib/ie/opaque_type.rb', line 26

def all
  @opaque_type_sym_to_i.key
end

.to_i(arg) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/ie/opaque_type.rb', line 39

def to_i(arg)
  return arg if arg.is_a?(Fixnum)
  if @opaque_type_sym_to_i.has_key?(arg)
    @opaque_type_sym_to_i[arg]
  else
    raise
  end
end

.to_sym(arg) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ie/opaque_type.rb', line 30

def to_sym(arg)
  return arg unless arg.is_a?(Fixnum)
  if @opaque_type_sym.has_key?(arg)
    @opaque_type_sym[arg]
  else
    raise
  end
end

Instance Method Details

#encodeObject Also known as: enc



71
72
73
# File 'lib/ie/opaque_type.rb', line 71

def encode
  [@opaque_type].pack('C')
end

#to_hashObject



76
77
78
# File 'lib/ie/opaque_type.rb', line 76

def to_hash
  to_sym
end

#to_iObject



60
61
62
# File 'lib/ie/opaque_type.rb', line 60

def to_i
  @opaque_type
end

#to_sObject



63
64
65
# File 'lib/ie/opaque_type.rb', line 63

def to_s
  self.class.to_s.split('::').last + ": #{to_sym}"
end

#to_symObject



67
68
69
# File 'lib/ie/opaque_type.rb', line 67

def to_sym
  OpaqueType.to_sym @opaque_type
end