Class: IPCat::Datacenters
- Inherits:
-
Object
- Object
- IPCat::Datacenters
- Defined in:
- lib/ipcat.rb
Instance Method Summary collapse
- #add(start, stop, _name, url = nil) ⇒ Object
- #find(ipstring) ⇒ Object
-
#initialize(file) ⇒ Datacenters
constructor
A new instance of Datacenters.
- #length ⇒ Object
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 |
#length ⇒ Object
31 32 33 |
# File 'lib/ipcat.rb', line 31 def length @starts.length end |