class Lib::BOOTP::Packet::ClientHardwareAddress
Public Class Methods
new(chaddr)
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 14 def initialize(chaddr) raise ArgumentError, "Can't convert #{chaddr.class.name} to String" unless chaddr.respond_to? :to_s clear_chaddr = chaddr.to_s.gsub(/([:\-.,])/, '').to_s raise ArgumentError, "Given CHADDR is to long: #{chaddr}" if clear_chaddr.size > 32 @chaddr = [clear_chaddr.ljust(32, '0')].pack('H32').unpack('C*') end
unpack(packet)
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 42 def self.unpack(packet) new packet.unpack('H32').first.to_s end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 29 def <=>(other) clear_other = other.to_s.gsub(/([:\-.,])/, '').to_s @chaddr <=> [clear_other.ljust(32, '0')].pack('H32').unpack('C*') end
pack()
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 38 def pack [@chaddr.map{ |item| item.to_s(16).rjust(2, '0') }.join('')].pack('H32') end
to_a()
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 34 def to_a @chaddr end
to_s(len = nil)
click to toggle source
# File lib/lib/bootp/packet/client_hardware_address.rb, line 21 def to_s(len = nil) unless len.nil? || len.is_a?(Integer) raise ArgumentError "Len must be a Integer or nil, #{len.class.name} given" end raise ArgumentError "Len out of range: #{len}" if len.to_i > 16 || len.to_i < 0 (len ? @chaddr[0..(len - 1)] : @chaddr).map{ |item| item.to_s(16).rjust(2, '0') }.join(':') end