Class: OSPFv2::LsAge

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/ie/ls_age.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(age = 0) ⇒ LsAge

Returns a new instance of LsAge.

Raises:

  • (ArgumentError)


47
48
49
50
# File 'lib/ie/ls_age.rb', line 47

def initialize(age=0)
  @age=age
  raise ArgumentError, "Invalid Argument #{age}" unless age.is_a?(Integer)
end

Class Attribute Details

._agingObject

Returns the value of attribute _aging.



29
30
31
# File 'lib/ie/ls_age.rb', line 29

def _aging
  @_aging
end

Class Method Details

.aging(arg = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/ie/ls_age.rb', line 33

def aging(arg=nil)
  if arg
    case arg
    when :on  ; self._aging = true
    when :off ; self._aging = false
    end
  else
    self._aging = ! _aging
  end
end

.aging?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ie/ls_age.rb', line 30

def aging?
  _aging
end

Instance Method Details

#-(obj) ⇒ Object



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

def -(obj)
  to_i - obj.to_i
end

#<=>(obj) ⇒ Object



78
79
80
# File 'lib/ie/ls_age.rb', line 78

def <=>(obj)
  to_i <=> obj.to_i
end

#aging?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ie/ls_age.rb', line 66

def aging?
  self.class.aging?
end

#encodeObject Also known as: enc



94
95
96
# File 'lib/ie/ls_age.rb', line 94

def encode
  [@age].pack('n')
end

#maxageObject



70
71
72
# File 'lib/ie/ls_age.rb', line 70

def maxage
  @age = OSPFv2::MaxAge
end

#maxaged?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/ie/ls_age.rb', line 74

def maxaged?
  to_i >= OSPFv2::MaxAge
end

#reset(age = nil) ⇒ Object



61
62
63
64
# File 'lib/ie/ls_age.rb', line 61

def reset(age=nil)
  @age = age if age
  @time=nil
end

#to_hashObject



99
100
101
# File 'lib/ie/ls_age.rb', line 99

def to_hash
  to_i
end

#to_iObject



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

def to_i
  if aging?
    @time ||= Time.now
    (Time.new - @time + @age).to_int
  else
    @age
  end
end

#to_sObject



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

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

#to_s_iosObject



90
91
92
# File 'lib/ie/ls_age.rb', line 90

def to_s_ios
  "LS age: #{to_i}"
end