class IpNumeric

Stores an IP address in numeric form.

IpNumeric instances are immutable, and memoize most of their methods.

Public Class Methods

from_dotted(dotted) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 106
def self.from_dotted(dotted)
  ip_a, ip_b, ip_c, ip_d = quads = dotted.split(".", 4).map(&:to_i)
  obj = new((ip_a << 24) + (ip_b << 16) + (ip_c << 8) + (ip_d))
  obj.instance_variable_set('@dotted', dotted.freeze)
  obj.instance_variable_set('@quads',  quads.freeze)
  obj
end
from_packed(pi) click to toggle source

class methods ===

# File lib/gorillib/model/type/ip_address.rb, line 102
def self.from_packed(pi)
  new(pi)
end
new(addr) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 79
def initialize(addr)
  @packed = addr.to_int
end

Public Instance Methods

+(int) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 87
def +(int)     ; self.class.new(to_int + int) ; end
<=>(other) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 86
def <=>(other) ; packed <=> other.to_int ; end
==(other) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 85
def ==(other)  ; packed  == other.to_int ; end
dotted() click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 92
def dotted
  @dotted ||= quads.join('.').freeze
end
packed() click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 90
def packed ; @packed ; end
quads() click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 96
def quads
  @quads ||= [ (@packed >> 24) & 0xFF, (@packed >> 16) & 0xFF, (@packed >>  8) & 0xFF, (@packed) & 0xFF ].freeze
end
receive(val) click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 75
def receive(val)
  new(val)
end
to_i() click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 83
def to_i       ; packed ; end
to_int() click to toggle source
# File lib/gorillib/model/type/ip_address.rb, line 84
def to_int     ; packed ; end