class Lib::BOOTP::Packet::Flags
Public Class Methods
new(flags=0)
click to toggle source
# 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
unpack(flags)
click to toggle source
# File lib/lib/bootp/packet/flags.rb, line 69 def self.unpack(flags) self.new flags.unpack('n').first end
Public Instance Methods
<=>(other)
click to toggle source
# 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()
click to toggle source
# File lib/lib/bootp/packet/flags.rb, line 57 def broadcast @flags[:b] end
broadcast?()
click to toggle source
# File lib/lib/bootp/packet/flags.rb, line 53 def broadcast? @flags[:b] == 1 ? true : false end
pack()
click to toggle source
# File lib/lib/bootp/packet/flags.rb, line 65 def pack [@flag.to_i].pack('n') end
to_s()
click to toggle source
# File lib/lib/bootp/packet/flags.rb, line 61 def to_s "0x#{@flag.to_s(16)}" end
Also aliased as: to_hex