Class: GeoipRedis::CityLoader
- Inherits:
-
Object
- Object
- GeoipRedis::CityLoader
- Defined in:
- lib/geoip_redis/city_loader.rb
Instance Method Summary collapse
-
#initialize(redis) ⇒ CityLoader
constructor
A new instance of CityLoader.
- #load_blocks(path_to_blocks) ⇒ Object
- #load_locations(path_to_locations) ⇒ Object
Constructor Details
#initialize(redis) ⇒ CityLoader
Returns a new instance of CityLoader.
8 9 10 11 12 13 |
# File 'lib/geoip_redis/city_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 21 22 23 |
# File 'lib/geoip_redis/city_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) locations = rows.map { |row| @blocks_parser.location(row) } @store.put_locations(locations) end end |
#load_locations(path_to_locations) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/geoip_redis/city_loader.rb', line 25 def load_locations(path_to_locations) read_by_batch(path_to_locations) do |rows| locations = rows.map { |row| @locations_parser.city(row) } @store.put_locations(locations) end end |