Class: Lib::BOOTP::Packet::IPAddress
- Inherits:
-
Object
- Object
- Lib::BOOTP::Packet::IPAddress
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/lib/bootp/packet/ip_address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(ip) ⇒ IPAddress
constructor
A new instance of IPAddress.
- #pack ⇒ Object
Constructor Details
#initialize(ip) ⇒ IPAddress
Returns a new instance of IPAddress.
18 19 20 21 22 23 24 25 26 |
# File 'lib/lib/bootp/packet/ip_address.rb', line 18 def initialize(ip) @ip = if ip.is_a?(IPAddr) ip else raise ArgumentError, "Wrong IP Address #{ip}" if ip.nil? || ip == '' IPAddr.new(ip, Socket::AF_INET) end raise ArgumentError, "Wrong IP Address #{ip}" unless @ip.is_a?(IPAddr) end |
Class Method Details
.unpack(ip) ⇒ Object
38 39 40 |
# File 'lib/lib/bootp/packet/ip_address.rb', line 38 def self.unpack(ip) new ip.to_s.unpack('N').first.to_i end |
Instance Method Details
#<=>(other) ⇒ Object
28 29 30 31 |
# File 'lib/lib/bootp/packet/ip_address.rb', line 28 def <=>(other) other = IPAddr.new(other, Socket::AF_INET) unless other.is_a?(IPAddr) self.to_i <=> other.to_i end |
#pack ⇒ Object
33 34 35 36 |
# File 'lib/lib/bootp/packet/ip_address.rb', line 33 def pack @ip = 0 if @ip.nil? [@ip.to_i].pack('N') end |