module Aws::Util

@api private

Public Class Methods

copy_hash(hash) click to toggle source
# File lib/aws-sdk-core/util.rb, line 18
def copy_hash(hash)
  if Hash === hash
    deep_copy(hash)
  else
    raise ArgumentError, "expected hash, got `#{hash.class}`"
  end
end
deep_copy(obj) click to toggle source
# File lib/aws-sdk-core/util.rb, line 26
def deep_copy(obj)
  case obj
  when nil then nil
  when true then true
  when false then false
  when Hash
    obj.inject({}) do |h, (k,v)|
      h[k] = deep_copy(v)
      h
    end
  when Array
    obj.map { |v| deep_copy(v) }
  else
    if obj.respond_to?(:dup)
      obj.dup
    elsif obj.respond_to?(:clone)
      obj.clone
    else
      obj
    end
  end
end
deep_merge(left, right) click to toggle source
# File lib/aws-sdk-core/util.rb, line 10
def deep_merge(left, right)
  case left
  when Hash then left.merge(right) { |key, v1, v2| deep_merge(v1, v2) }
  when Array then right + left
  else right
  end
end
deserialize_number(str) click to toggle source

@param [String] str @return [Number] The input as a number

# File lib/aws-sdk-core/util.rb, line 83
def deserialize_number(str)
  case str
  when 'Infinity' then ::Float::INFINITY
  when '-Infinity' then -::Float::INFINITY
  when 'NaN' then ::Float::NAN
  when nil then nil
  else str.to_f
  end
end
deserialize_time(value) click to toggle source

@param [String] value @return [Time]

# File lib/aws-sdk-core/util.rb, line 95
def deserialize_time(value)
  case value
  when nil then nil
  when /^[\d.]+$/ then Time.at(value.to_f).utc
  else
    begin
      fractional_time = Time.parse(value).to_f
      Time.at(fractional_time).utc
    rescue ArgumentError
      raise "unhandled timestamp format `#{value}'"
    end
  end
end
monotonic_milliseconds() click to toggle source
# File lib/aws-sdk-core/util.rb, line 49
def monotonic_milliseconds
  if defined?(Process::CLOCK_MONOTONIC)
    Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
  else
    DateTime.now.strftime('%Q').to_i
  end
end
monotonic_seconds() click to toggle source
# File lib/aws-sdk-core/util.rb, line 57
def monotonic_seconds
  monotonic_milliseconds / 1000.0
end
serialize_number(input) click to toggle source

@param [Number] input @return [Number, String] The serialized number

# File lib/aws-sdk-core/util.rb, line 72
def serialize_number(input)
  if input == ::Float::INFINITY then 'Infinity'
  elsif input == -::Float::INFINITY then '-Infinity'
  elsif input&.nan? then 'NaN'
  else
    input
  end
end
str_2_bool(str) click to toggle source
# File lib/aws-sdk-core/util.rb, line 61
def str_2_bool(str)
  case str.to_s
  when "true" then true
  when "false" then false
  else
    nil
  end
end