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.



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

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



14
15
16
17
# File 'lib/ipcat.rb', line 14

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



19
20
21
22
23
# File 'lib/ipcat.rb', line 19

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

#lengthObject



25
26
27
# File 'lib/ipcat.rb', line 25

def length
  @starts.length
end