Class: WhichTime
- Inherits:
-
Object
- Object
- WhichTime
- Defined in:
- lib/which_time.rb,
lib/which_time/version.rb
Constant Summary collapse
- VERSION =
"1.0.4"
Class Method Summary collapse
Instance Method Summary collapse
- #coordinates ⇒ Object
-
#initialize(address, params = {api_key: nil, time: Time.now, http_proxy: nil}) ⇒ WhichTime
constructor
A new instance of WhichTime.
- #location ⇒ Object
- #proxy_host ⇒ Object
- #proxy_port ⇒ Object
- #time ⇒ Object
- #timezone ⇒ Object
Constructor Details
#initialize(address, params = {api_key: nil, time: Time.now, http_proxy: nil}) ⇒ WhichTime
Returns a new instance of WhichTime.
5 6 7 8 9 10 |
# File 'lib/which_time.rb', line 5 def initialize address, params={api_key: nil, time: Time.now, http_proxy: nil} @address = address @api_key = params[:api_key] @timestamp = params[:time].to_i @proxy = params[:http_proxy] end |
Class Method Details
.in(address, params = {api_key: nil, time: Time.now, http_proxy: nil}) ⇒ Object
28 29 30 |
# File 'lib/which_time.rb', line 28 def self.in address, params={api_key: nil, time: Time.now, http_proxy: nil} new(address, params).time end |
Instance Method Details
#coordinates ⇒ Object
16 17 18 |
# File 'lib/which_time.rb', line 16 def coordinates location.values.join(',') end |
#location ⇒ Object
12 13 14 |
# File 'lib/which_time.rb', line 12 def location @location ||= get_location['results'][0]['geometry']['location'] end |
#proxy_host ⇒ Object
32 33 34 |
# File 'lib/which_time.rb', line 32 def proxy_host URI.parse(@proxy).host if @proxy end |
#proxy_port ⇒ Object
36 37 38 |
# File 'lib/which_time.rb', line 36 def proxy_port URI.parse(@proxy).port if @proxy end |
#time ⇒ Object
24 25 26 |
# File 'lib/which_time.rb', line 24 def time Time.at(@timestamp).in_time_zone timezone end |
#timezone ⇒ Object
20 21 22 |
# File 'lib/which_time.rb', line 20 def timezone @timezone ||= get_timezone['timeZoneId'] end |