Module: Geo
- Extended by:
- Instance
- Defined in:
- lib/geo.rb,
lib/geo.rb,
lib/geo/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .cities(pattern = nil, &block) ⇒ Object
-
.city(ip) ⇒ Object
lookup the IP in the GeoLiteCity database on city level.
Class Method Details
.cities(pattern = nil, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/geo.rb', line 59 def self.cities(pattern=nil, &block) expect! pattern => [ nil, Regexp, String ] pattern = Regexp.compile("^" + Regexp.escape(pattern) + "$") if pattern.is_a?(String) ary = [] collect = block || ary.method(:push) instance.each do |rec| next if pattern && rec.city_name !~ pattern collect.call complete_city(rec) end block ? self : ary end |
.city(ip) ⇒ Object
lookup the IP in the GeoLiteCity database on city level.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/geo.rb', line 14 def self.city(ip) # Use some global IP if we are running locally. if !ip || ip == "127.0.0.1" ip = "193.99.144.85" end if city = instance.city(ip) complete_city(city) end end |