Class: Lib::BOOTP::Packet::OpCode
- Inherits:
-
Object
- Object
- Lib::BOOTP::Packet::OpCode
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/lib/bootp/packet/op_code.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(op = 1) ⇒ OpCode
constructor
A new instance of OpCode.
- #pack ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(op = 1) ⇒ OpCode
Returns a new instance of OpCode.
18 19 20 21 |
# File 'lib/lib/bootp/packet/op_code.rb', line 18 def initialize(op=1) raise ArgumentError, "OP Code out of range : #{op}" unless [1,2].include? op.to_i @op = op end |
Class Method Details
.unpack(op) ⇒ Object
40 41 42 |
# File 'lib/lib/bootp/packet/op_code.rb', line 40 def self.unpack(op) self.new op.unpack('C').first end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 34 |
# File 'lib/lib/bootp/packet/op_code.rb', line 31 def <=>(other) return self.to_i <=> other if other.is_a?(Integer) self.to_s <=> other.to_s.upcase end |
#pack ⇒ Object
36 37 38 |
# File 'lib/lib/bootp/packet/op_code.rb', line 36 def pack [@op.to_i].pack('C') end |
#to_s ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/lib/bootp/packet/op_code.rb', line 23 def to_s if @op == 1 'BOOTREQUEST' elsif @op == 2 'BOOTREPLY' end end |