class Amplitude::Formatter

Public Class Methods

add_insert_id(data) click to toggle source
# File lib/amplitude/formatter.rb, line 40
def add_insert_id(data)
  return data if data[:insert_id] || Amplitude.config.iid_generator.nil?
  data[:insert_id] = Amplitude.config.iid_generator.call()
  data
end
call(data) click to toggle source
# File lib/amplitude/formatter.rb, line 3
def call(data)
  data = sanitize_data(data)
  data = format_data(data)
  add_insert_id(data)
end
format_data(data) click to toggle source
# File lib/amplitude/formatter.rb, line 13
def format_data(data)
  format_props(format_time(data))
end
format_if_present(data, key, formatter) click to toggle source
# File lib/amplitude/formatter.rb, line 34
def format_if_present(data, key, formatter)
  return data unless data[key]
  data[key] = formatter.call(data[key])
  data
end
format_props(data) click to toggle source
# File lib/amplitude/formatter.rb, line 21
def format_props(data)
  data = format_if_present(
    data,
    :event_properties,
    event_prop_formatter
  )
  format_if_present(
    data,
    :user_properties,
    user_prop_formatter
  )
end
format_time(data) click to toggle source
# File lib/amplitude/formatter.rb, line 17
def format_time(data)
  format_if_present(data, :time, time_formatter)
end
sanitize_data(data) click to toggle source
# File lib/amplitude/formatter.rb, line 9
def sanitize_data(data)
  Amplitude::HashSlicer.call(data, Amplitude.config.whitelist)
end

Protected Class Methods

event_prop_formatter() click to toggle source
# File lib/amplitude/formatter.rb, line 52
def event_prop_formatter
  Amplitude.config.event_prop_formatter
end
time_formatter() click to toggle source
# File lib/amplitude/formatter.rb, line 48
def time_formatter
  Amplitude.config.time_formatter
end
user_prop_formatter() click to toggle source
# File lib/amplitude/formatter.rb, line 56
def user_prop_formatter
  Amplitude.config.user_prop_formatter
end