Class: SNMP::TimeTicks

Inherits:
UnsignedInteger show all
Defined in:
lib/snmp/varbind.rb

Instance Method Summary collapse

Methods inherited from UnsignedInteger

decode, #initialize

Methods inherited from Integer

#<=>, #coerce, decode, #initialize, #to_f, #to_i, #to_oid

Methods included from BER::Decode

#assert_no_remainder, #build_integer, #decode_integer, #decode_integer_value, #decode_ip_address, #decode_object_id, #decode_object_id_value, #decode_octet_string, #decode_sequence, #decode_timeticks, #decode_tlv, #decode_uinteger_value

Methods included from BER::Encode

#encode_exception, #encode_integer, #encode_length, #encode_null, #encode_object_id, #encode_octet_string, #encode_sequence, #encode_tagged_integer, #encode_tlv, #integer_to_octets

Constructor Details

This class inherits a constructor from SNMP::UnsignedInteger

Instance Method Details

#asn1_typeObject


402
403
404
# File 'lib/snmp/varbind.rb', line 402

def asn1_type
  "TimeTicks"
end

#encodeObject


406
407
408
# File 'lib/snmp/varbind.rb', line 406

def encode
  encode_tagged_integer(BER::TimeTicks_TAG, @value)
end

#to_sObject


410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/snmp/varbind.rb', line 410

def to_s
  days, remainder = @value.divmod(8640000)
  hours, remainder = remainder.divmod(360000)
  minutes, remainder = remainder.divmod(6000)
  seconds, hundredths = remainder.divmod(100)
  case
  when days < 1
    sprintf('%02d:%02d:%02d.%02d',
            hours, minutes, seconds, hundredths)
  when days == 1
    sprintf('1 day, %02d:%02d:%02d.%02d',
            hours, minutes, seconds, hundredths)
  when days > 1
    sprintf('%d days, %02d:%02d:%02d.%02d',
            days, hours, minutes, seconds, hundredths)
  end
end