Class: Rudder::Analytics::FieldParser
- Inherits:
-
Object
- Object
- Rudder::Analytics::FieldParser
- Extended by:
- Utils
- Defined in:
- lib/rudder/analytics/field_parser.rb
Overview
Handles parsing fields according to the RudderStack Spec
Constant Summary
Constants included from Utils
Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON
Class Method Summary collapse
-
.parse_for_alias(fields) ⇒ Object
In addition to the common fields, alias accepts:.
-
.parse_for_group(fields) ⇒ Object
In addition to the common fields, group accepts:.
-
.parse_for_identify(fields) ⇒ Object
In addition to the common fields, identify accepts:.
-
.parse_for_page(fields) ⇒ Object
In addition to the common fields, page accepts:.
-
.parse_for_screen(fields) ⇒ Object
In addition to the common fields, screen accepts:.
-
.parse_for_track(fields) ⇒ Object
In addition to the common fields, track accepts:.
Methods included from Utils
check_string, date_in_iso8601, datetime_in_iso8601, formatted_offset, isoify_dates, isoify_dates!, seconds_to_utc_offset, stringify_keys, symbolize_keys, symbolize_keys!, time_in_iso8601, uid
Class Method Details
.parse_for_alias(fields) ⇒ Object
In addition to the common fields, alias accepts:
-
“previous_id”
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rudder/analytics/field_parser.rb', line 52 def parse_for_alias(fields) common = parse_common_fields(fields) previous_id = fields[:previous_id] check_presence!(previous_id, 'previous_id') check_string(previous_id, 'previous_id') common.merge({ :type => 'alias', :previousId => previous_id }) end |
.parse_for_group(fields) ⇒ Object
In addition to the common fields, group accepts:
-
“group_id”
-
“traits”
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rudder/analytics/field_parser.rb', line 69 def parse_for_group(fields) common = parse_common_fields(fields) group_id = fields[:group_id] check_presence!(group_id, 'group_id') check_string(group_id, 'group_id') common.merge({ :type => 'group', :groupId => group_id }) end |
.parse_for_identify(fields) ⇒ Object
In addition to the common fields, identify accepts:
-
“traits”
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rudder/analytics/field_parser.rb', line 31 def parse_for_identify(fields) common = parse_common_fields(fields) # add the traits if present if fields[:traits] traits = fields[:traits] context = common[:context].merge({ :traits => traits }) common = common.merge({ :context => context }) end common.merge({ :type => 'identify' }) end |
.parse_for_page(fields) ⇒ Object
In addition to the common fields, page accepts:
-
“name”
-
“properties”
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rudder/analytics/field_parser.rb', line 86 def parse_for_page(fields) common = parse_common_fields(fields) name = fields[:name] || '' properties = common[:properties] || {} properties = properties.merge({ :name => name }) common.merge({ :type => 'page', :name => name, :event => name, :properties => properties }) end |
.parse_for_screen(fields) ⇒ Object
In addition to the common fields, screen accepts:
-
“name”
-
“properties”
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rudder/analytics/field_parser.rb', line 105 def parse_for_screen(fields) common = parse_common_fields(fields) name = fields[:name] properties = common[:properties] || {} properties = properties.merge({ :name => name }) category = fields[:category] check_presence!(name, 'name') parsed = common.merge({ :type => 'screen', :name => name, :event => name, :properties => properties }) parsed[:category] = category if category parsed end |
.parse_for_track(fields) ⇒ Object
In addition to the common fields, track accepts:
-
“event”
-
“properties”
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rudder/analytics/field_parser.rb', line 16 def parse_for_track(fields) common = parse_common_fields(fields) event = fields[:event] check_presence!(event, 'event') common.merge({ :type => 'track', :event => event.to_s }) end |