Class: OSPFv2::LsType

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IE

#method_missing

Constructor Details

#initialize(ls_type = 1) ⇒ LsType

Returns a new instance of LsType.



137
138
139
140
141
142
143
144
145
146
# File 'lib/ie/ls_type.rb', line 137

def initialize(ls_type=1)
  @ls_type = case ls_type
  when Symbol
    LsType.ls_type_sym_to_i(ls_type)
  when Fixnum
    ls_type
  else
    raise ArgumentError, "Invalid LsType #{ls_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



82
83
84
# File 'lib/ie/ls_type.rb', line 82

def all
  [:router, :network, :summary, :asbr_summary, :as_external, :area]
end

.ls_type_sym_to_i(arg) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/ie/ls_type.rb', line 100

def ls_type_sym_to_i(arg)
  return arg if arg.is_a?(Fixnum)
  if @ls_type_sym_to_i.has_key?(arg)
    @ls_type_sym_to_i[arg]
  else
    raise "cannot convert #{arg.inspect} to i"
  end
end

.to_i(arg) ⇒ Object



86
87
88
89
# File 'lib/ie/ls_type.rb', line 86

def to_i(arg)
  return arg unless arg.is_a?(Symbol)
  ls_type_sym_to_i(arg)
end

.to_junos(arg) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/ie/ls_type.rb', line 109

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

.to_s_ios(arg) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/ie/ls_type.rb', line 118

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

.to_short(arg) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/ie/ls_type.rb', line 127

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

.to_sym(arg) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/ie/ls_type.rb', line 91

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

Instance Method Details

#encodeObject Also known as: enc



158
159
160
# File 'lib/ie/ls_type.rb', line 158

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

#is_opaque?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/ie/ls_type.rb', line 77

def is_opaque?
  (9..11) === @ls_type
end

#to_hashObject



163
164
165
# File 'lib/ie/ls_type.rb', line 163

def to_hash
  to_sym
end

#to_iObject



147
148
149
# File 'lib/ie/ls_type.rb', line 147

def to_i
  @ls_type
end

#to_junosObject



175
176
177
# File 'lib/ie/ls_type.rb', line 175

def to_junos
  LsType.to_junos(to_i)
end

#to_sObject



150
151
152
# File 'lib/ie/ls_type.rb', line 150

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

#to_s_iosObject



171
172
173
# File 'lib/ie/ls_type.rb', line 171

def to_s_ios
  "LS Type: " + LsType.to_s_ios(to_i)
end

#to_s_shortObject



167
168
169
# File 'lib/ie/ls_type.rb', line 167

def to_s_short
  LsType.to_short(to_i)
end

#to_symObject



154
155
156
# File 'lib/ie/ls_type.rb', line 154

def to_sym
  LsType.to_sym @ls_type
end