Class: GeoipRedis::CountryLoader

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

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ CountryLoader

Returns a new instance of CountryLoader.



8
9
10
11
12
13
# File 'lib/geoip_redis/country_loader.rb', line 8

def initialize(redis)
  @store = Store.new(redis)
  @csv_reader = CSVReader.new
  @blocks_parser = BlocksParser.new
  @locations_parser = LocationsParser.new
end

Instance Method Details

#load_blocks(path_to_blocks) ⇒ Object



15
16
17
18
19
20
# File 'lib/geoip_redis/country_loader.rb', line 15

def load_blocks(path_to_blocks)
  read_by_batch(path_to_blocks) do |rows|
    ip_ranges = rows.map { |row| @blocks_parser.ip_range(row) }
    @store.put_ip_ranges(ip_ranges)
  end
end

#load_locations(path_to_locations) ⇒ Object



22
23
24
25
26
27
# File 'lib/geoip_redis/country_loader.rb', line 22

def load_locations(path_to_locations)
  read_by_batch(path_to_locations) do |rows|
    locations = rows.map { |row| @locations_parser.country(row) }
    @store.put_locations(locations)
  end
end