Class: ChartMogul::Utils::JSONParser

Inherits:
Object
  • Object
show all
Defined in:
lib/chartmogul/utils/json_parser.rb

Class Method Summary collapse

Class Method Details

.opt_string_to_time(value) ⇒ Object



18
19
20
21
22
# File 'lib/chartmogul/utils/json_parser.rb', line 18

def opt_string_to_time(value)
  return value unless value.instance_of?(String)

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

.parse(json_string) ⇒ Object



5
6
7
8
# File 'lib/chartmogul/utils/json_parser.rb', line 5

def parse(json_string)
  hash = JSON.parse(json_string, symbolize_names: true)
  HashSnakeCaser.new(hash).to_snake_keys
end

.typecast_custom_attributes(custom_attributes) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/chartmogul/utils/json_parser.rb', line 10

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