Class: IPCat::IPRange

Inherits:
Object
  • Object
show all
Defined in:
lib/ipcat/iprange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, last, name = nil, url = nil) ⇒ IPRange

Returns a new instance of IPRange.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/ipcat/iprange.rb', line 7

def initialize(first, last, name = nil, url = nil)
  @first = IPCat.ip_to_integer(first)
  @last  = IPCat.ip_to_integer(last)
  @name = name
  @url = url
  raise ArgumentError, 'first must be <= last' if @first > @last
end

Instance Attribute Details

#firstObject

Returns the value of attribute first.



5
6
7
# File 'lib/ipcat/iprange.rb', line 5

def first
  @first
end

#lastObject

Returns the value of attribute last.



5
6
7
# File 'lib/ipcat/iprange.rb', line 5

def last
  @last
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ipcat/iprange.rb', line 5

def name
  @name
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/ipcat/iprange.rb', line 5

def url
  @url
end

Instance Method Details

#<=>(obj) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ipcat/iprange.rb', line 15

def <=>(obj)
  case obj
  when Integer
    compare_with_integer(obj)
  when IPRange
    # Assume all IPRanges are non-overlapping
    first <=> obj.first
  end
end