Module: WhereTZ
Overview
Instance Method Summary collapse
-
#get(lat, lng) ⇒ TZInfo::DataTimezone, ...
TZInfo::DataTimezone
object by coordinates. -
#lookup(lat, lng) ⇒ String, ...
Time zone name by coordinates.
Instance Method Details
#get(lat, lng) ⇒ TZInfo::DataTimezone, ...
TZInfo::DataTimezone
object by coordinates.
Note that you should add tzinfo
to your Gemfile to use this method.
wheretz
doesn't depend on tzinfo
by itself.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wheretz.rb', line 57 def get(lat, lng) begin require 'tzinfo' rescue LoadError raise LoadError, 'Please install tzinfo for using #get' end name = lookup(lat, lng) case name when String TZInfo::Timezone.get(name) when Array name.map(&TZInfo::Timezone.method(:get)) end end |
#lookup(lat, lng) ⇒ String, ...
Time zone name by coordinates.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wheretz.rb', line 35 def lookup(lat, lng) candidates = FILES.select { |_f, _z, xr, yr| xr.cover?(lng) && yr.cover?(lat) } case candidates.size when 0 then nil when 1 then candidates.first[1] else lookup_geo(lat, lng, candidates) end end |