class NETSNMP::Timetick

Public Class Methods

new(ticks) click to toggle source

@param [Integer] ticks number of microseconds since the time it was read

# File lib/netsnmp/timeticks.rb, line 6
def initialize(ticks)
  @ticks = ticks
end

Public Instance Methods

*(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 42
def *(other)
  Timetick.new((to_i * other.to_i))
end
+(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 34
def +(other)
  Timetick.new((to_i + other.to_i))
end
-(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 38
def -(other)
  Timetick.new((to_i - other.to_i))
end
/(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 46
def /(other)
  Timetick.new((to_i / other.to_i))
end
<=>(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 30
def <=>(other)
  to_i <=> other.to_i
end
coerce(other) click to toggle source
# File lib/netsnmp/timeticks.rb, line 26
def coerce(other)
  [Timetick.new(other), self]
end
to_asn() click to toggle source
# File lib/netsnmp/timeticks.rb, line 22
def to_asn
  OpenSSL::ASN1::ASN1Data.new([@ticks].pack("N"), 3, :APPLICATION)
end
to_i() click to toggle source
# File lib/netsnmp/timeticks.rb, line 18
def to_i
  @ticks
end
to_s() click to toggle source
# 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

Private Instance Methods

days_since() click to toggle source
# File lib/netsnmp/timeticks.rb, line 52
def days_since
  Rational(@ticks, 8_640_000)
end
hours_since(days) click to toggle source
# File lib/netsnmp/timeticks.rb, line 56
def hours_since(days)
  Rational((days.to_f - days.to_i) * 24)
end
milliseconds_since(minutes) click to toggle source
# File lib/netsnmp/timeticks.rb, line 64
def milliseconds_since(minutes)
  Rational((minutes.to_f - minutes.to_i) * 60)
end
minutes_since(hours) click to toggle source
# File lib/netsnmp/timeticks.rb, line 60
def minutes_since(hours)
  Rational((hours.to_f - hours.to_i) * 60)
end