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)


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

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

Instance Attribute Details

#firstObject

Returns the value of attribute first.



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

def first
  @first
end

#lastObject

Returns the value of attribute last.



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

def last
  @last
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#<=>(obj) ⇒ Object



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

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