Class: WhichTime

Inherits:
Object
  • Object
show all
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

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

#coordinatesObject



16
17
18
# File 'lib/which_time.rb', line 16

def coordinates
  location.values.join(',')
end

#locationObject



12
13
14
# File 'lib/which_time.rb', line 12

def location
  @location ||= get_location['results'][0]['geometry']['location']
end

#proxy_hostObject



32
33
34
# File 'lib/which_time.rb', line 32

def proxy_host   
  URI.parse(@proxy).host if @proxy
end

#proxy_portObject



36
37
38
# File 'lib/which_time.rb', line 36

def proxy_port    
  URI.parse(@proxy).port if @proxy
end

#timeObject



24
25
26
# File 'lib/which_time.rb', line 24

def time
  Time.at(@timestamp).in_time_zone timezone
end

#timezoneObject



20
21
22
# File 'lib/which_time.rb', line 20

def timezone
  @timezone ||= get_timezone['timeZoneId']
end