Created
September 20, 2011 19:21
-
-
Save bkimble/1230051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ree-1.8.7-2011.03 :001 > GeoIpBlock.count | |
=> 6055096 | |
ree-1.8.7-2011.03 :005 > GeoIpBlock.first.e.class.name | |
=> "Fixnum" | |
ree-1.8.7-2011.03 :006 > res = Benchmark.measure { puts GeoLocation.by_ip('74.220.125.3').location }; puts res | |
San Francisco, CA | |
0.000000 0.000000 0.000000 ( 0.003826) | |
if , using mongo, I can find the first geo_ip_block that has an IP address thats end range is greater than or equal to this decimal IP
and if my geo_ip_block object has a start value that is less than or equal to this decimal IP address
return the geo ip block that I found
otherwise return null
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def self.locate(decimal_ip)
if block = where(:e.gte => decimal_ip).order("e ASC").limit(1).first
return block if block.s <= decimal_ip
end
end