Class: OSPFv2::Id
  
  
  
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods included from IE
  #method_missing
  Constructor Details
  
    
  
  
    #initialize(arg = 0)  ⇒ Id 
  
  
  
  
    
Returns a new instance of Id.
   
 
  
  
    | 
42
43
44 | # File 'lib/ie/id.rb', line 42
def initialize(arg=0)
  self.id = arg
end | 
 
  
 
  Dynamic Method Handling
  
    This class handles dynamic methods through the method_missing method
    
      in the class OSPFv2::IE
    
  
  
 
  
    Class Method Details
    
      
  
  
    .new_ntoh(s)  ⇒ Object 
  
  
  
  
    | 
32
33
34
35 | # File 'lib/ie/id.rb', line 32
def self.new_ntoh(s)
  return unless s.is_a?(String)
  new s.unpack('N')[0]
end | 
 
    
      
  
  
    | 
37
38
39
40 | # File 'lib/ie/id.rb', line 37
def self.to_i(id)
  return id.to_i unless id.is_a?(String) and id.split('.').size==4
  IPAddr.new(id).to_i
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #encode  ⇒ Object 
  
  
    Also known as:
    enc
    
  
  
  
    | 
63
64
65 | # File 'lib/ie/id.rb', line 63
def encode
  [@id].pack('N')
end | 
 
    
      
  
  
    | 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | # File 'lib/ie/id.rb', line 46
def id=(val)
  if val.is_a?(Hash)
    @id = val[:id] if val[:id]
  elsif val.is_a?(IPAddr)
    @id = val.to_i
  elsif val.is_a?(Integer)
    raise ArgumentError, "Invalid Argument #{val}" unless (0..0xffffffff).include?(val)
    @id = val
  elsif val.is_a?(String)
    @id = IPAddr.new(val).to_i
  elsif val.is_a?(Id)
    @id = val.to_i
  else
    raise ArgumentError, "Invalid Argument #{val.inspect}"
  end
end | 
 
    
      
  
  
    | 
76
77
78 | # File 'lib/ie/id.rb', line 76
def to_hash
  to_s_short
end | 
 
    
      
  
  
    | 
68
69
70 | # File 'lib/ie/id.rb', line 68
def to_i
  @id
end | 
 
    
      
  
  
    | 
80
81
82 | # File 'lib/ie/id.rb', line 80
def to_ip
  to_s(false)
end | 
 
    
      
  
  
    #to_s(verbose = true)  ⇒ Object 
  
  
  
  
    | 
72
73
74 | # File 'lib/ie/id.rb', line 72
def to_s(verbose=true)
  verbose ? to_s_verbose : to_s_short
end |