Class: NETSNMP::Timetick

Inherits:
Numeric
  • Object
show all
Defined in:
lib/netsnmp/timeticks.rb

Instance Method Summary collapse

Constructor Details

#initialize(ticks) ⇒ Timetick

Returns a new instance of Timetick.

Parameters:

  • ticks (Integer)

    number of microseconds since the time it was read



6
7
8
9
# File 'lib/netsnmp/timeticks.rb', line 6

def initialize(ticks)
  @ticks = ticks
  super()
end

Instance Method Details

#*(other) ⇒ Object



43
44
45
# File 'lib/netsnmp/timeticks.rb', line 43

def *(other)
  Timetick.new((to_i * other.to_i))
end

#+(other) ⇒ Object



35
36
37
# File 'lib/netsnmp/timeticks.rb', line 35

def +(other)
  Timetick.new((to_i + other.to_i))
end

#-(other) ⇒ Object



39
40
41
# File 'lib/netsnmp/timeticks.rb', line 39

def -(other)
  Timetick.new((to_i - other.to_i))
end

#/(other) ⇒ Object



47
48
49
# File 'lib/netsnmp/timeticks.rb', line 47

def /(other)
  Timetick.new((to_i / other.to_i))
end

#<=>(other) ⇒ Object



31
32
33
# File 'lib/netsnmp/timeticks.rb', line 31

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

#coerce(other) ⇒ Object



27
28
29
# File 'lib/netsnmp/timeticks.rb', line 27

def coerce(other)
  [Timetick.new(other), self]
end

#to_asnObject



23
24
25
# File 'lib/netsnmp/timeticks.rb', line 23

def to_asn
  OpenSSL::ASN1::ASN1Data.new([@ticks].pack("N"), 3, :APPLICATION)
end

#to_iObject



19
20
21
# File 'lib/netsnmp/timeticks.rb', line 19

def to_i
  @ticks
end

#to_sObject



11
12
13
14
15
16
17
# File 'lib/netsnmp/timeticks.rb', line 11

def to_s
  days = days_since
  hours = hours_since(days)
  minutes = minutes_since(hours)
  milliseconds = milliseconds_since(minutes)
  "Timeticks: (#{@ticks}) #{days.to_i} days, #{hours.to_i}:#{minutes.to_i}:#{milliseconds.to_f.round(2)}"
end