Sha256: 2cdea8f5c556c6c49d506e5ab8f5447f0f235562716eb050e2e1fe228ef1c9ea
Contents?: true
Size: 919 Bytes
Versions: 16
Compression:
Stored size: 919 Bytes
Contents
# frozen_string_literal: true module ChartMogul module Utils class JSONParser class << self def parse(json_string, immutable_keys: []) hash = JSON.parse(json_string, symbolize_names: true) HashSnakeCaser.new(hash, immutable_keys: immutable_keys).to_snake_keys end def typecast_custom_attributes(custom_attributes) return {} unless custom_attributes custom_attributes.each_with_object({}) do |(key, value), hash| hash[key] = opt_string_to_time(value) end end def opt_string_to_time(value) return value unless value.instance_of?(String) parse_timestamp(value) rescue ArgumentError value end def parse_timestamp(value) Time.iso8601(value) rescue ArgumentError Time.rfc2822(value) end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems