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

- (IP) initialize(input)

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

- (Object) bytes (readonly)

Returns the value of attribute bytes



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

def bytes
  @bytes
end

Instance Method Details

- (Object) ==(other)



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

def == other
  bytes == other.bytes
end

- (Object) next



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

def next
  offset_by(1)
end

- (Object) prev



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

def prev
  offset_by(-1)
end

- (Object) to_s



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

def to_s
  bytes.join '.'
end

- (Boolean) valid?

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