Method: GeoIP#each

Defined in:
lib/geoip.rb

#eachObject

Iterate through a GeoIP city database by



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/geoip.rb', line 455

def each
  return enum_for unless block_given?

  if (@database_type != Edition::CITY_REV0 &&
      @database_type != Edition::CITY_REV1)
    throw "Invalid GeoIP database type, can't iterate thru non-City database"
  end

  @iter_pos = @database_segments[0] + 1
  num = 0

  until ((rec = read_city(@iter_pos)).nil?)
    yield rec
    print "#{num}: #{@iter_pos}\n" if((num += 1) % 1000 == 0)
  end

  @iter_pos = nil
  return self
end