Class: Babushka::IP

Inherits:
Object show all
Defined in:
lib/babushka/ip.rb

Direct Known Subclasses

IPRange

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ IP

Returns a new instance of IP.



5
6
7
# File 'lib/babushka/ip.rb', line 5

def initialize input
  @bytes = sanitize input
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



3
4
5
# File 'lib/babushka/ip.rb', line 3

def bytes
  @bytes
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/babushka/ip.rb', line 13

def == other
  bytes == other.bytes
end

#nextObject



22
23
24
# File 'lib/babushka/ip.rb', line 22

def next
  offset_by(1)
end

#prevObject



26
27
28
# File 'lib/babushka/ip.rb', line 26

def prev
  offset_by(-1)
end

#to_sObject



9
10
11
# File 'lib/babushka/ip.rb', line 9

def to_s
  bytes.join '.'
end

#valid?Boolean

Returns whether this IP should be considered a valid one for a client to be using.

Returns:

  • (Boolean)


18
19
20
# File 'lib/babushka/ip.rb', line 18

def valid?
  [:public, :private, :loopback].include? describe
end