Module: Lsaws::Utils
- Included in:
- Lister
- Defined in:
- lib/lsaws/utils.rb
Instance Method Summary collapse
- #_deep_transform_keys_in_object(object, &block) ⇒ Object
-
#_deep_transform_keys_in_object!(object, &block) ⇒ Object
copypasted from lib/active_support/core_ext/hash/keys.rb.
-
#from_iso8601(s) ⇒ Object
“2022-11-15T10:49:00+00:00” => “2022-11-15 10:49:00 UTC”.
-
#to_iso8601(s) ⇒ Object
“2022-11-15 10:49:00 UTC” => “2022-11-15T10:49:00+00:00”.
Instance Method Details
#_deep_transform_keys_in_object(object, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lsaws/utils.rb', line 21 def _deep_transform_keys_in_object(object, &block) case object when Hash object.each_with_object(object.class.new) do |(key, value), result| result[yield(key)] = _deep_transform_keys_in_object(value, &block) end when Array object.map { |e| _deep_transform_keys_in_object(e, &block) } else object end end |
#_deep_transform_keys_in_object!(object, &block) ⇒ Object
copypasted from lib/active_support/core_ext/hash/keys.rb
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lsaws/utils.rb', line 6 def _deep_transform_keys_in_object!(object, &block) case object when Hash object.each_key do |key| value = object.delete(key) object[yield(key)] = _deep_transform_keys_in_object!(value, &block) end object when Array object.map! { |e| _deep_transform_keys_in_object!(e, &block) } else object end end |
#from_iso8601(s) ⇒ Object
“2022-11-15T10:49:00+00:00” => “2022-11-15 10:49:00 UTC”
40 41 42 |
# File 'lib/lsaws/utils.rb', line 40 def from_iso8601(s) s.gsub(/([0-9-]{10})T([0-9:]+{8})\+00:00/, '\1 \2 UTC') end |
#to_iso8601(s) ⇒ Object
“2022-11-15 10:49:00 UTC” => “2022-11-15T10:49:00+00:00”
35 36 37 |
# File 'lib/lsaws/utils.rb', line 35 def to_iso8601(s) s.gsub(/([0-9-]{10}) ([0-9:]+{8}) UTC/, '\1T\2+00:00') end |