Class: OSPFv2::LsAge

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(age = 0) ⇒ LsAge

Returns a new instance of LsAge.

Raises:

  • (ArgumentError)


43
44
45
46
47
# File 'lib/ie/ls_age.rb', line 43

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

Class Method Details

.aging(state = :off) ⇒ Object



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

def aging(state=:off)
  case state
  when :on   ; @aging = true
  when :off  ; @aging = false
  else
    raise ArgumentError, "Invalid Argument"
  end
end

.aging?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ie/ls_age.rb', line 38

def aging?
  @aging
end

Instance Method Details

#-(obj) ⇒ Object



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

def -(obj)
  to_i - obj.to_i
end

#<=>(obj) ⇒ Object



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

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

#aging?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ie/ls_age.rb', line 53

def aging?
  self.class.aging?
end

#encodeObject Also known as: enc



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

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

#maxageObject



57
58
59
# File 'lib/ie/ls_age.rb', line 57

def maxage
  @age = OSPFv2::MaxAge
end

#maxaged?Boolean

Returns:

  • (Boolean)


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

def maxaged?
  to_i >= OSPFv2::MaxAge
end

#to_hashObject



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

def to_hash
  to_i
end

#to_iObject



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

def to_i
  aging? ? (Time.new - @time + @age).to_int : @age
end

#to_sObject



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

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