Pure Ruby MaxMind DB binary file reader.
Add this line to your application's Gemfile:
gem 'maxminddb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install maxminddb
db = MaxMindDB.new('./GeoLite2-City.mmdb')
ret = db.lookup('74.125.225.224')
ret.found? # => true
ret.country.name # => 'United States'
ret.country.name('zh-CN') # => '美国'
ret.country.iso_code # => 'US'
ret.city.name(:fr) # => 'Mountain View'
ret.location.latitude # => -122.0574
Even if no result could be found, you can ask for the attributes without guarding for nil:
db = MaxMindDB.new('./GeoLite2-City.mmdb')
ret = db.lookup('127.0.0.1')
ret.found? # => false
ret.country.name # => nil
- Fork it ( http://github.com/yhirose/maxminddb/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request