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
# File 'lib/netsnmp/timeticks.rb', line 6

def initialize(ticks)
  @ticks = ticks
end

Instance Method Details

#*(other) ⇒ Object



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

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

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#/(other) ⇒ Object



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

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

#<=>(other) ⇒ Object



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

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

#coerce(other) ⇒ Object



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

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

#to_asnObject



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

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

#to_iObject



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

def to_i
  @ticks
end

#to_sObject



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

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