Class: GeoipRedis::Resolver

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

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Resolver

Returns a new instance of Resolver.



7
8
9
# File 'lib/geoip_redis/resolver.rb', line 7

def initialize(redis)
  @store = Store.new(redis)
end

Instance Method Details

#resolve(ip) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/geoip_redis/resolver.rb', line 11

def resolve(ip)
  ip_num = normalize_ip(ip).to_i
  ip_range = @store.find_ip_range(ip_num)

  return if ip_range.nil? || !ip_range.member?(ip_num)

  @store.find_location(ip_range.location_id)
end