Class: IpAddress
Constant Summary
IpAddresslike::ONES
Class Method Summary
collapse
Instance Method Summary
collapse
#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
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
38
39
40
|
# File 'lib/gorillib/type/ip_address.rb', line 38
def dotted
self
end
|
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
|
52
53
54
|
# File 'lib/gorillib/type/ip_address.rb', line 52
def quads
self.split(".", 4).map{|qq| Integer(qq) }
end
|
42
43
44
|
# File 'lib/gorillib/type/ip_address.rb', line 42
def to_i
packed
end
|