Class: Lib::BOOTP::Packet::Flags
- Inherits:
-
Object
- Object
- Lib::BOOTP::Packet::Flags
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/lib/bootp/packet/flags.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #broadcast ⇒ Object
- #broadcast? ⇒ Boolean
-
#initialize(flags = 0) ⇒ Flags
constructor
A new instance of Flags.
- #pack ⇒ Object
- #to_s ⇒ Object (also: #to_hex)
Constructor Details
#initialize(flags = 0) ⇒ Flags
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lib/bootp/packet/flags.rb', line 18 def initialize(flags=0) @flags = {} @flag = 0 if flags.is_a? Integer case flags when 0x8000 @flags[:b] = 1 @flag = 0x8000 when 0 @flags[:b] = 0 @flag = 0 else raise ArgumentError, "Unknown flags value #{flags}" end elsif flags.is_a? Symbol case flags when :broadcast @flags[:b] = 1 @flag = 0x8000 when :unicast @flags[:b] = 0 @flag = 0 else raise ArgumentError, "Unknown flags value #{flags}" end else raise ArgumentError, 'FLAGS must by an Integer or Symbol' unless flags.is_a?(Integer) or flags.is_a?(Symbol) end end |
Class Method Details
.unpack(flags) ⇒ Object
69 70 71 |
# File 'lib/lib/bootp/packet/flags.rb', line 69 def self.unpack(flags) self.new flags.unpack('n').first end |
Instance Method Details
#<=>(other) ⇒ Object
48 49 50 51 |
# File 'lib/lib/bootp/packet/flags.rb', line 48 def <=>(other) other = Lib::BOOTP::Packet::Flags.new(other) unless other.is_a?(Lib::BOOTP::Packet::Flags) self.to_i <=> other.to_i end |
#broadcast ⇒ Object
57 58 59 |
# File 'lib/lib/bootp/packet/flags.rb', line 57 def broadcast @flags[:b] end |
#broadcast? ⇒ Boolean
53 54 55 |
# File 'lib/lib/bootp/packet/flags.rb', line 53 def broadcast? @flags[:b] == 1 ? true : false end |
#pack ⇒ Object
65 66 67 |
# File 'lib/lib/bootp/packet/flags.rb', line 65 def pack [@flag.to_i].pack('n') end |
#to_s ⇒ Object Also known as: to_hex
61 62 63 |
# File 'lib/lib/bootp/packet/flags.rb', line 61 def to_s "0x#{@flag.to_s(16)}" end |