Class: OSPFv2::LsAge

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

Instance Method Summary collapse

Constructor Details

#initialize(age = 0) ⇒ LsAge

Returns a new instance of LsAge.

Raises:

  • (ArgumentError)


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

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

Instance Method Details

#-(obj) ⇒ Object



55
56
57
# File 'lib/ie/ls_age.rb', line 55

def -(obj)
  to_i - obj.to_i
end

#<=>(obj) ⇒ Object



51
52
53
# File 'lib/ie/ls_age.rb', line 51

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

#aging?Boolean

Returns:

  • (Boolean)


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

def aging?
  true
end

#encodeObject Also known as: enc



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

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

#maxageObject



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

def maxage
  @age = OSPFv2::MaxAge
end

#maxaged?Boolean

Returns:

  • (Boolean)


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

def maxaged?
  to_i >= OSPFv2::MaxAge
end

#to_hashObject



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

def to_hash
  to_i
end

#to_iObject



35
36
37
# File 'lib/ie/ls_age.rb', line 35

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

#to_sObject



59
60
61
# File 'lib/ie/ls_age.rb', line 59

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