forked from chrisyour/geo_location
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Released GeoLocation version 0.2.0: now with timezones, more tests, a…
…nd an updated README
- Loading branch information
Showing
8 changed files
with
904 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require 'active_support/inflector' | ||
|
||
require 'geo_location/variables' | ||
require 'geo_location/geo_location' | ||
require 'geo_location/version' | ||
require 'geo_location/timezones' | ||
require 'geo_location/geo_location' | ||
require 'geo_location/variables' |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module GeoLocation | ||
|
||
class << self | ||
|
||
def timezone(country, region=nil) | ||
build_timezones | ||
return nil if GeoLocation::timezones.empty? | ||
(region.nil? || region.empty?) ? GeoLocation::timezones[country.to_sym] : GeoLocation::timezones[country.to_sym][region.to_sym] | ||
end | ||
|
||
private | ||
|
||
def build_timezones | ||
if GeoLocation::timezones.empty? | ||
data = {} | ||
|
||
File.open("lib/geo_location/timezones.txt", "r") do |infile| | ||
while (line = infile.gets) | ||
zones = line.split("\n") | ||
zones.each do |z| | ||
zone = z.split(" ") | ||
country = zone[0].to_sym | ||
region = zone[1].to_sym | ||
value = zone[2] | ||
|
||
data[country] = {} if data[country].nil? | ||
if region.to_s.empty? | ||
data[country] = value | ||
else | ||
data[country][region] = value | ||
end | ||
|
||
end # end zones.each | ||
end # end while | ||
end # end file.open | ||
|
||
GeoLocation::timezones = data | ||
end # end unless | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.