module TzLookupWrapper
Extracted from github.com/panthomakos/timezone/blob/master/lib/timezone/active_support.rb Copyright © 2011 Panayiotis Thomakos github.com/panthomakos/timezone/blob/master/License.txt
Constants
- NODE_BIN
- TZ_LOOKUP_PATH
- VERSION
Public Class Methods
lookup(lat_r,lng_r)
click to toggle source
Lookup a timezone
Example:
>> TzLookupWrapper.lookup(43.7, -79.4) => "America/Toronto"
Arguments:
latitude: (Float) longitude: (Float)
# File lib/tz_lookup_wrapper.rb, line 28 def self.lookup(lat_r,lng_r) lat = Float lat_r lng = Float lng_r script = <<-HEREDOC try { process.stdout.write(require("#{TZ_LOOKUP_PATH}")(#{lat}, #{lng})); } catch (ex) { process.stdout.write(ex.message); process.exit(code=1) } HEREDOC result = nil IO.popen(NODE_BIN, 'r+') do |io| io.puts(script) io.close_write result = io.gets end if $?.success? result else raise TzLookupWrapperException.new result || "Empty output" end end