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

Constructor Details

This class inherits a constructor from SNMP::UnsignedInteger

Instance Method Details

#asn1_typeObject



357
358
359
# File 'lib/snmp/varbind.rb', line 357

def asn1_type
    "TimeTicks"
end

#encodeObject



361
362
363
# File 'lib/snmp/varbind.rb', line 361

def encode
    encode_tagged_integer(TimeTicks_TAG, @value)
end

#to_sObject



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/snmp/varbind.rb', line 365

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