Class: Amplitude::Formatter
- Inherits:
-
Object
- Object
- Amplitude::Formatter
- Defined in:
- lib/amplitude/formatter.rb
Class Method Summary collapse
- .add_insert_id(data) ⇒ Object
- .call(data) ⇒ Object
- .format_data(data) ⇒ Object
- .format_if_present(data, key, formatter) ⇒ Object
- .format_props(data) ⇒ Object
- .format_time(data) ⇒ Object
- .sanitize_data(data) ⇒ Object
Class Method Details
.add_insert_id(data) ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object
3 4 5 6 7 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/amplitude/formatter.rb', line 13 def format_data(data) format_props(format_time(data)) end |
.format_if_present(data, key, formatter) ⇒ Object
34 35 36 37 38 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/amplitude/formatter.rb', line 17 def format_time(data) format_if_present(data, :time, time_formatter) end |
.sanitize_data(data) ⇒ Object
9 10 11 |
# File 'lib/amplitude/formatter.rb', line 9 def sanitize_data(data) Amplitude::HashSlicer.call(data, Amplitude.config.whitelist) end |