Module: Brow::Utils
Constant Summary collapse
- UTC_OFFSET_WITH_COLON =
Internal
'%s%02d:%02d'
- UTC_OFFSET_WITHOUT_COLON =
Internal
UTC_OFFSET_WITH_COLON.sub(':', '')
Instance Method Summary collapse
-
#date_in_iso8601(date) ⇒ Object
Internal.
-
#datetime_in_iso8601(datetime) ⇒ Object
Internal.
-
#formatted_offset(time, colon = true, alternate_utc_string = nil) ⇒ Object
Internal.
-
#isoify_dates(hash) ⇒ Object
Internal: Returns a new hash with all the date values in the into iso8601 strings.
-
#seconds_to_utc_offset(seconds, colon = true) ⇒ Object
Internal.
-
#symbolize_keys(hash) ⇒ Object
Internal: Return a new hash with keys converted from strings to symbols.
-
#time_in_iso8601(time) ⇒ Object
Internal.
Instance Method Details
#date_in_iso8601(date) ⇒ Object
Internal
44 45 46 |
# File 'lib/brow/utils.rb', line 44 def date_in_iso8601(date) date.strftime('%F') end |
#datetime_in_iso8601(datetime) ⇒ Object
Internal
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/brow/utils.rb', line 25 def datetime_in_iso8601(datetime) case datetime when Time time_in_iso8601 datetime when DateTime time_in_iso8601 datetime.to_time when Date date_in_iso8601 datetime else datetime end end |
#formatted_offset(time, colon = true, alternate_utc_string = nil) ⇒ Object
Internal
49 50 51 |
# File 'lib/brow/utils.rb', line 49 def formatted_offset(time, colon = true, alternate_utc_string = nil) time.utc? && alternate_utc_string || seconds_to_utc_offset(time.utc_offset, colon) end |
#isoify_dates(hash) ⇒ Object
Internal: Returns a new hash with all the date values in the into iso8601 strings
18 19 20 21 22 |
# File 'lib/brow/utils.rb', line 18 def isoify_dates(hash) hash.each_with_object({}) do |(k, v), memo| memo[k] = datetime_in_iso8601(v) end end |
#seconds_to_utc_offset(seconds, colon = true) ⇒ Object
Internal
54 55 56 |
# File 'lib/brow/utils.rb', line 54 def seconds_to_utc_offset(seconds, colon = true) (colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON) % [(seconds < 0 ? '-' : '+'), (seconds.abs / 3600), ((seconds.abs % 3600) / 60)] end |
#symbolize_keys(hash) ⇒ Object
Internal: Return a new hash with keys converted from strings to symbols
10 11 12 13 14 |
# File 'lib/brow/utils.rb', line 10 def symbolize_keys(hash) hash.each_with_object({}) do |(k, v), memo| memo[k.to_sym] = v end end |
#time_in_iso8601(time) ⇒ Object
Internal
39 40 41 |
# File 'lib/brow/utils.rb', line 39 def time_in_iso8601(time) "#{time.strftime('%Y-%m-%dT%H:%M:%S.%6N')}#{formatted_offset(time, true, 'Z')}" end |