Class: Lib::BOOTP::Packet::HopCount
- Inherits:
-
Object
- Object
- Lib::BOOTP::Packet::HopCount
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/lib/bootp/packet/hop_count.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(hops = 0) ⇒ HopCount
constructor
A new instance of HopCount.
- #pack ⇒ Object
Constructor Details
#initialize(hops = 0) ⇒ HopCount
Returns a new instance of HopCount.
18 19 20 21 |
# File 'lib/lib/bootp/packet/hop_count.rb', line 18 def initialize(hops=0) @hops = hops.to_i #.is_a?(Hash) ? hops.transform_keys(&:to_sym)[:code].to_i : hops.to_i raise ArgumentError, "Hop Count out of range: #{@hops}" if @hops > 255 end |
Class Method Details
.unpack(hops) ⇒ Object
31 32 33 |
# File 'lib/lib/bootp/packet/hop_count.rb', line 31 def self.unpack(hops) self.new hops.unpack('C').first end |
Instance Method Details
#<=>(other) ⇒ Object
23 24 25 |
# File 'lib/lib/bootp/packet/hop_count.rb', line 23 def <=>(other) self.to_i <=> other.to_i end |
#pack ⇒ Object
27 28 29 |
# File 'lib/lib/bootp/packet/hop_count.rb', line 27 def pack [@hops.to_i].pack('C') end |