Sha256: 1a1bd121193e34c55bff18a346f8d89a3e4c1634a916cd63507a69b5b9f73419

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

module ChartMogul
  module Utils
    class JSONParser
      class << self
        def parse(json_string)
          hash = JSON.parse(json_string, symbolize_names: true)
          HashSnakeCaser.new(hash).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)

          Time.iso8601(value) rescue Time.rfc2822(value) rescue value
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chartmogul-ruby-1.6.4 lib/chartmogul/utils/json_parser.rb
chartmogul-ruby-1.6.3 lib/chartmogul/utils/json_parser.rb
chartmogul-ruby-1.6.2 lib/chartmogul/utils/json_parser.rb
chartmogul-ruby-1.6.1 lib/chartmogul/utils/json_parser.rb