Class: Eztz::TimeZoneResponse
- Inherits:
-
Object
- Object
- Eztz::TimeZoneResponse
- Defined in:
- lib/eztz/response.rb
Overview
Encapsulates the data from the timezone api
Instance Attribute Summary collapse
-
#dst_offset ⇒ Integer
readonly
The offset for daylight-savings time in seconds.
-
#error_message ⇒ String
readonly
More detailed information about the reasons behind the given status code, if other than OK.
-
#id ⇒ String
readonly
A string containing the ID of the time zone, such as “America/Los_Angeles” or “Australia/Sydney”.
-
#name ⇒ String
readonly
A string containing the long form name of the time zone.
-
#raw_offset ⇒ Integer
readonly
The offset from UTC (in seconds) for the given location.
-
#status ⇒ String
readonly
A string indicating the status of the response.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(timestamp, response) ⇒ TimeZoneResponse
constructor
A new instance of TimeZoneResponse.
-
#local_time ⇒ Time
The local time of the location is the sum of the :timestamp, :dst_offset and :raw_offset.
- #success? ⇒ Boolean
-
#to_h ⇒ Hash
The object as a Hash.
Constructor Details
#initialize(timestamp, response) ⇒ TimeZoneResponse
43 44 45 46 47 48 49 50 |
# File 'lib/eztz/response.rb', line 43 def initialize(, response) = @dst_offset, , @raw_offset, @status, @id, @name = response.values_at( 'dstOffset', 'error_message', 'rawOffset', 'status', 'timeZoneId', 'timeZoneName' ) end |
Instance Attribute Details
#dst_offset ⇒ Integer (readonly)
38 39 40 |
# File 'lib/eztz/response.rb', line 38 def dst_offset @dst_offset end |
#error_message ⇒ String (readonly)
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
#id ⇒ String (readonly)
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
#name ⇒ String (readonly)
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
#raw_offset ⇒ Integer (readonly)
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
#status ⇒ String (readonly)
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
38 39 |
# File 'lib/eztz/response.rb', line 38 attr_reader :dst_offset, :error_message, :id, :name, :raw_offset, :status, :timestamp |
Instance Method Details
#local_time ⇒ Time
The local time of the location is the sum of the :timestamp, :dst_offset and :raw_offset.
59 60 61 |
# File 'lib/eztz/response.rb', line 59 def local_time Time.at(.to_i + dst_offset.to_i + raw_offset.to_i) end |
#success? ⇒ Boolean
52 53 54 |
# File 'lib/eztz/response.rb', line 52 def success? status == 'OK' end |
#to_h ⇒ Hash
The object as a Hash.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/eztz/response.rb', line 65 def to_h { dst_offset: dst_offset, error_message: , id: id, name: name, raw_offset: raw_offset, status: status, timestamp: } end |