Class: IpAddress

Inherits:
String show all
Includes:
IpAddresslike
Defined in:
lib/gorillib/type/extended.rb,
lib/gorillib/type/ip_address.rb

Constant Summary

Constants included from IpAddresslike

IpAddresslike::ONES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IpAddresslike

#bitness_max, #bitness_min, #to_hex, #to_s

Methods inherited from String

#blank?, #camelize, #constantize, #demodulize, #humanize, #safe_constantize, #snakeize, #titleize, #truncate, #underscore

Class Method Details

.from_dotted(str) ⇒ Object



63
64
65
# File 'lib/gorillib/type/ip_address.rb', line 63

def self.from_dotted(str)
  new(str)
end

.from_packed(pi) ⇒ Object

=== class methods ===



58
59
60
61
# File 'lib/gorillib/type/ip_address.rb', line 58

def self.from_packed(pi)
  str = [ (pi >> 24) & 0xFF, (pi >> 16) & 0xFF, (pi >>  8) & 0xFF, (pi) & 0xFF ].join(".")
  new(str)
end

Instance Method Details

#dottedObject



38
39
40
# File 'lib/gorillib/type/ip_address.rb', line 38

def dotted
  self
end

#packedObject



47
48
49
50
# File 'lib/gorillib/type/ip_address.rb', line 47

def packed
  ip_a, ip_b, ip_c, ip_d = quads
  ((ip_a << 24) + (ip_b << 16) + (ip_c << 8) + (ip_d))
end

#quadsObject



52
53
54
# File 'lib/gorillib/type/ip_address.rb', line 52

def quads
  self.split(".", 4).map{|qq| Integer(qq) }
end

#to_iObject



42
43
44
# File 'lib/gorillib/type/ip_address.rb', line 42

def to_i
  packed
end