Class: IPCat::Datacenters

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

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Datacenters

Returns a new instance of Datacenters.



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

def initialize(file)
  @urls = []
  @blocks = org.ipcat.Blocks.new
  File.open(file, 'r').readlines.map do |line|
    add(*line.chomp.split(','))
  end
end

Instance Method Details

#add(start, stop, _name, url = nil) ⇒ Object



16
17
18
19
# File 'lib/ipcat.rb', line 16

def add(start, stop, _name, url = nil)
  @urls << url
  @blocks.add org.ipcat.IP.parseIp(start), org.ipcat.IP.parseIp(stop)
end

#find(ipstring) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/ipcat.rb', line 21

def find(ipstring)
  return nil if ipstring.nil?
  begin
    n = @blocks.find(org.ipcat.IP.parseIp(ipstring))
    return @urls[n] unless n == -1
  rescue NumberFormatException => e
    return nil
  end
end

#lengthObject



31
32
33
# File 'lib/ipcat.rb', line 31

def length
  @starts.length
end