Module: Pont::Attribution

Defined in:
lib/pont/attribution.rb

Overview

A module for manipulating request-parameter attribution values

Class Method Summary collapse

Class Method Details

.clean(input, logger = nil) ⇒ Hash

clean is a shared method for cleaning up attribution values to ensure our Prospects#attribution column contains only the data we choose.

Parameters:

  • Key (Hash, ActionController::Parameters, String)

    value pairs with attribution data

Returns:

  • (Hash)

    cleaned up attribution data as a Hash



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pont/attribution.rb', line 13

def self.clean(input, logger = nil)
  parsed_input = input.is_a?(String) ? JSON.parse(input) : input

  return {} if parsed_input.nil?

  parsed_input.slice(*permitted_keys)
rescue JSON::ParserError, TypeError => e
  logger&.error("#{e.class}: #{e.message} input: (#{input})")

  {}
end