evva 0.2.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +10 -10
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +3 -6
  5. data/README.md +3 -2
  6. data/changelog.md +18 -2
  7. data/lib/evva/{mixpanel_enum.rb → analytics_enum.rb} +2 -1
  8. data/lib/evva/analytics_event.rb +17 -0
  9. data/lib/evva/analytics_property.rb +17 -0
  10. data/lib/evva/android_generator.rb +142 -84
  11. data/lib/evva/config.rb +12 -2
  12. data/lib/evva/google_sheet.rb +43 -25
  13. data/lib/evva/swift_generator.rb +91 -81
  14. data/lib/evva/templates/kotlin/base.kt +7 -0
  15. data/lib/evva/templates/kotlin/destinations.kt +5 -0
  16. data/lib/evva/templates/kotlin/event_enum.kt +5 -0
  17. data/lib/evva/templates/kotlin/events.kt +36 -0
  18. data/lib/evva/templates/kotlin/people_properties.kt +26 -0
  19. data/lib/evva/templates/kotlin/people_properties_enum.kt +5 -0
  20. data/lib/evva/templates/kotlin/special_property_enums.kt +10 -0
  21. data/lib/evva/templates/swift/base.swift +7 -0
  22. data/lib/evva/templates/swift/destinations.swift +5 -0
  23. data/lib/evva/templates/swift/events.swift +66 -0
  24. data/lib/evva/templates/swift/people_properties.swift +50 -0
  25. data/lib/evva/templates/swift/special_property_enums.swift +10 -0
  26. data/lib/evva/version.rb +2 -2
  27. data/lib/evva.rb +14 -4
  28. data/spec/evva_spec.rb +3 -5
  29. data/spec/fixtures/sample_public_events.csv +4 -4
  30. data/spec/fixtures/sample_public_people_properties.csv +4 -3
  31. data/spec/fixtures/test.yml +5 -3
  32. data/spec/lib/evva/android_generator_spec.rb +163 -69
  33. data/spec/lib/evva/config_spec.rb +7 -3
  34. data/spec/lib/evva/google_sheet_spec.rb +25 -7
  35. data/spec/lib/evva/swift_generator_spec.rb +157 -40
  36. metadata +17 -6
  37. data/.ruby-version +0 -1
  38. data/evva_config.yml +0 -14
  39. data/lib/evva/mixpanel_event.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9078e38ca6bba5b85a3349fb9e1c3f9c31b8de357080ffb1ab105e6bcbbdaa1
4
- data.tar.gz: 16b264637125fafdc14a991a9cb984e440b948bdc7d934776329b8aa8ef2d89f
3
+ metadata.gz: 9b5e24a443e11f788768884a4830e8731d4f7f0cbeb02c66e613bb293809b82a
4
+ data.tar.gz: 5ccb08d43adccc135c64d3ae9bb06c19cb811c0a8a1a5b647cafdab2370fdaa0
5
5
  SHA512:
6
- metadata.gz: 6efc1abd4ea8d72f7ac2edeccbf111deac25922fa0b1464d754d21e7bfef921efffddd228bb6d6913f3b64a4acfcd8763082f0b36b16e85e28b930d933df879c
7
- data.tar.gz: 77a4ad5df7074b646def8c880654b551fcde2e10523e3dec622d202fba48ac7bdda6d1a882abcd5c54bc2e6175b2bb68a52c30ab77d1c522f29362bc9a297db3
6
+ metadata.gz: ee89843173f05753970aacb497add3a0408bbebd2ba6c4d757c41c3f3b0ba90fa00e28dcf455069e1b81e348ef8ceac1c91c01a4369a7fb903b4497ba8bc9b5c
7
+ data.tar.gz: eb3281e5f3ee84bec798731117504c2e6fdddfc035e772ed13b025a6f506111b4e81875f4126c74fe4582e0bc5fe2aa4b32be29c6f39edb72cbb291192ad424b
data/.rubocop_todo.yml CHANGED
@@ -57,8 +57,8 @@ Layout/EmptyLinesAroundBlockBody:
57
57
  Layout/EmptyLinesAroundClassBody:
58
58
  Exclude:
59
59
  - 'lib/evva/android_generator.rb'
60
- - 'lib/evva/mixpanel_enum.rb'
61
- - 'lib/evva/mixpanel_event.rb'
60
+ - 'lib/evva/analytics_enum.rb'
61
+ - 'lib/evva/analytics_event.rb'
62
62
 
63
63
  # Offense count: 1
64
64
  # Cop supports --auto-correct.
@@ -163,8 +163,8 @@ Layout/TrailingBlankLines:
163
163
  - 'lib/evva/enum_generator.rb'
164
164
  - 'lib/evva/event_generator.rb'
165
165
  - 'lib/evva/google_sheet.rb'
166
- - 'lib/evva/mixpanel_enum.rb'
167
- - 'lib/evva/mixpanel_event.rb'
166
+ - 'lib/evva/analytics_enum.rb'
167
+ - 'lib/evva/analytics_event.rb'
168
168
  - 'spec/lib/evva/enum_generator_spec.rb'
169
169
  - 'spec/lib/evva/event_generator_spec.rb'
170
170
  - 'spec/lib/evva/google_sheet_spec.rb'
@@ -226,8 +226,8 @@ Lint/UselessAssignment:
226
226
  # Offense count: 2
227
227
  Lint/Void:
228
228
  Exclude:
229
- - 'lib/evva/mixpanel_enum.rb'
230
- - 'lib/evva/mixpanel_event.rb'
229
+ - 'lib/evva/analytics_enum.rb'
230
+ - 'lib/evva/analytics_event.rb'
231
231
 
232
232
  # Offense count: 8
233
233
  Metrics/AbcSize:
@@ -309,8 +309,8 @@ Style/Documentation:
309
309
  - 'lib/evva/event_generator.rb'
310
310
  - 'lib/evva/google_sheet.rb'
311
311
  - 'lib/evva/logger.rb'
312
- - 'lib/evva/mixpanel_enum.rb'
313
- - 'lib/evva/mixpanel_event.rb'
312
+ - 'lib/evva/analytics_enum.rb'
313
+ - 'lib/evva/analytics_event.rb'
314
314
 
315
315
  # Offense count: 1
316
316
  # Cop supports --auto-correct.
@@ -407,8 +407,8 @@ Style/RaiseArgs:
407
407
  # Cop supports --auto-correct.
408
408
  Style/RedundantSelf:
409
409
  Exclude:
410
- - 'lib/evva/mixpanel_enum.rb'
411
- - 'lib/evva/mixpanel_event.rb'
410
+ - 'lib/evva/analytics_enum.rb'
411
+ - 'lib/evva/analytics_event.rb'
412
412
  - 'lib/evva/object_extension.rb'
413
413
 
414
414
  # Offense count: 1
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.7.3'
3
2
 
4
3
  gem 'colorize'
5
4
  gem 'safe_yaml'
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.5.2)
5
- public_suffix (>= 2.0.2, < 4.0)
4
+ addressable (2.8.0)
5
+ public_suffix (>= 2.0.2, < 5.0)
6
6
  ast (2.3.0)
7
7
  colorize (0.8.1)
8
8
  crack (0.4.3)
@@ -15,7 +15,7 @@ GEM
15
15
  parser (2.4.0.0)
16
16
  ast (~> 2.2)
17
17
  powerpack (0.1.1)
18
- public_suffix (3.0.0)
18
+ public_suffix (4.0.6)
19
19
  rainbow (2.2.2)
20
20
  rake
21
21
  rake (12.3.3)
@@ -71,8 +71,5 @@ DEPENDENCIES
71
71
  simplecov-rcov
72
72
  webmock (~> 1.20)
73
73
 
74
- RUBY VERSION
75
- ruby 2.7.3p183
76
-
77
74
  BUNDLED WITH
78
75
  2.2.26
data/README.md CHANGED
@@ -24,7 +24,6 @@ Evva automatically generates code for triggering events based on a Google Sheets
24
24
 
25
25
  data_source:
26
26
  type: google_sheet
27
- sheet_id: <GOOGLE-DRIVE-SHEET-ID>
28
27
  events_url: <GOOGLE-DRIVE-EVENTS-SHEET-URL>
29
28
  people_properties_url: <GOOGLE-DRIVE-PEOPLE-PROPERTIES-SHEET-URL>
30
29
  enum_classes_url: <GOOGLE-DRIVE-ENUM-CLASSES-SHEET-URL>
@@ -33,5 +32,7 @@ Evva automatically generates code for triggering events based on a Google Sheets
33
32
  event_file_name: /file/with/tracking/functions
34
33
  event_enum_file_name: /file/with/event/names
35
34
  people_file_name: /file/with/people/properties
36
- special_enum_file_name: //file/with/special/enum/properties/
35
+ people_file_name: /file/with/people/property/names
36
+ destinations_file_name: /file/with/destinations
37
+ special_enum_file_name: /file/with/special/enum/properties/
37
38
  ```
data/changelog.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Change Log
2
2
 
3
- ## [0.2.0] - 2021/08/30
3
+ ## Unreleased
4
+
5
+
6
+ ## [0.4.2] - 2022-01-05
7
+ - Fix kotlin generation changes in 0.4.0
8
+
9
+ ## [0.4.1] - 2021-12-23
10
+ - Changes swift implementation so that destinations belong to EventType/PropertyType instead of Event/Property
11
+
12
+ ## [0.4.0] - 2021-12-21
13
+ - Adds type to people properties
14
+ - Adds a list of destinations to events and people properties
15
+
16
+ ## [0.3.0] - 2021-12-16
17
+ - Revamp Android generator to generate events as classes instead of methods.
18
+
19
+ ## [0.2.0] - 2021-08-30
4
20
  - Google Spreadsheet option stopped working due to a change in the API. This version fixes that.
5
21
 
6
22
  Note: You'll need a new setup. View README.
@@ -32,6 +48,6 @@ Note: You'll need a new setup. View README.
32
48
  ## [0.1.1] - 2017-11-07
33
49
  - Fixes mismatch between file name and class name generated.
34
50
 
35
- ## [0.1.0] - 2017/10/26
51
+ ## [0.1.0] - 2017-10-26
36
52
  - Initial Release.
37
53
 
@@ -1,6 +1,7 @@
1
1
  module Evva
2
- class MixpanelEnum
2
+ class AnalyticsEnum
3
3
  attr_reader :enum_name, :values
4
+
4
5
  def initialize(enum_name, values)
5
6
  @enum_name = enum_name
6
7
  @values = values
@@ -0,0 +1,17 @@
1
+ module Evva
2
+ class AnalyticsEvent
3
+ attr_reader :event_name, :properties, :destinations
4
+
5
+ def initialize(event_name, properties, destinations)
6
+ @event_name = event_name
7
+ @properties = properties
8
+ @destinations = destinations
9
+ end
10
+
11
+ def ==(other)
12
+ event_name == other.event_name &&
13
+ properties == other.properties &&
14
+ destinations == other.destinations
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Evva
2
+ class AnalyticsProperty
3
+ attr_reader :property_name, :type, :destinations
4
+
5
+ def initialize(property_name, type, destinations)
6
+ @property_name = property_name
7
+ @type = type
8
+ @destinations = destinations
9
+ end
10
+
11
+ def ==(other)
12
+ property_name == other.property_name &&
13
+ type == other.type &&
14
+ destinations == other.destinations
15
+ end
16
+ end
17
+ end
@@ -6,126 +6,184 @@ module Evva
6
6
  @package_name = package_name
7
7
  end
8
8
 
9
- IMPORT_EVENT = "import packagename.Event".freeze
10
- IMPORT_MASK = "import packagename.MixpanelAnalyticsMask".freeze
11
- IMPORT_JSON = "import org.json.JSONObject".freeze
9
+ BASE_TEMPLATE = File.expand_path("./templates/kotlin/base.kt", __dir__)
10
+ EVENTS_TEMPLATE = File.expand_path("./templates/kotlin/events.kt", __dir__)
11
+ EVENT_ENUM_TEMPLATE = File.expand_path("./templates/kotlin/event_enum.kt", __dir__)
12
+ PEOPLE_PROPERTIES_TEMPLATE = File.expand_path("./templates/kotlin/people_properties.kt", __dir__)
13
+ PEOPLE_PROPERTIES_ENUM_TEMPLATE = File.expand_path("./templates/kotlin/people_properties_enum.kt", __dir__)
14
+ SPECIAL_PROPERTY_ENUMS_TEMPLATE = File.expand_path("./templates/kotlin/special_property_enums.kt", __dir__)
15
+ DESTINATIONS_TEMPLATE = File.expand_path("./templates/kotlin/destinations.kt", __dir__)
12
16
 
13
- NATIVE_TYPES = %w[Long Int String Double Float Boolean].freeze
17
+ TAB_SIZE = " " # \t -> 4 spaces
14
18
 
15
- def events(bundle, file_name)
16
- header_footer_wrapper([IMPORT_EVENT, IMPORT_MASK, IMPORT_JSON]) do
17
- """open class #{file_name}(private val mask: MixpanelAnalyticsMask) {
19
+ NATIVE_TYPES = %w[Long Int String Double Float Boolean Date].freeze
18
20
 
19
- #{bundle.map { |e| kotlin_function(e) }.join("\n\n")}
21
+ def events(bundle, file_name, enums_file_name, destinations_file_name)
22
+ header_footer_wrapper do
23
+ class_name = file_name
24
+ enums_class_name = enums_file_name
25
+ destinations_class_name = destinations_file_name
26
+
27
+ events = bundle.map do |event|
28
+ properties = event.properties.map do |name, type|
29
+ type = native_type(type)
30
+
31
+ param_name = camelize(name.to_s, false)
32
+ value_fetcher = param_name
33
+
34
+ if is_special_property?(type)
35
+ if type.end_with?('?')
36
+ # optional value, we need ? to access a parameter
37
+ value_fetcher += "?"
38
+ end
39
+ value_fetcher += ".key"
40
+ end
41
+
42
+ {
43
+ param_name: param_name,
44
+ value_fetcher: value_fetcher,
45
+ type: type,
46
+ name: name.to_s,
47
+ }
48
+ end
49
+
50
+ destinations = event.destinations.map { |p| constantize(p) }
20
51
 
21
- \topen fun updateProperties(property: MixpanelProperties, value: Any) {
22
- \t\tmask.updateProperties(property.key, value)
23
- \t}
52
+ {
53
+ class_name: camelize(event.event_name),
54
+ event_name: constantize(event.event_name),
55
+ properties: properties,
56
+ destinations: destinations
57
+ }
58
+ end
24
59
 
25
- \topen fun incrementCounter(property: MixpanelProperties) {
26
- \t\tmask.incrementCounter(property.key)
27
- \t}
28
- }"""
60
+ template_from(EVENTS_TEMPLATE).result(binding)
29
61
  end
30
62
  end
31
63
 
32
- def people_properties(people_bundle, file_name)
64
+ def event_enum(bundle, file_name)
33
65
  header_footer_wrapper do
34
- body = "enum class MixpanelProperties(val key: String) {\n"
35
- body << people_bundle.map { |prop| "\t#{prop.upcase}(\"#{prop}\")" }.join(",\n")
36
- body << ";\n}"
66
+ class_name = file_name
67
+
68
+ events = bundle.map(&:event_name).map do |event_name|
69
+ {
70
+ name: constantize(event_name),
71
+ value: event_name,
72
+ }
73
+ end
74
+
75
+ template_from(EVENT_ENUM_TEMPLATE).result(binding)
37
76
  end
38
77
  end
39
78
 
40
- def event_enum(bundle, file_name)
41
- header_footer_wrapper([IMPORT_EVENT]) do
42
- body = "enum class #{file_name}(override val key: String) : Event {\n"
43
- body << bundle.map(&:event_name).map { |prop| "\t#{prop.upcase}(\"#{prop}\")" }.join(",\n")
44
- body << ";\n}"
79
+ def people_properties(people_bundle, file_name, enums_file_name, destinations_file_name)
80
+ header_footer_wrapper do
81
+ class_name = file_name
82
+ enums_class_name = enums_file_name
83
+ destinations_class_name = destinations_file_name
84
+
85
+ properties = people_bundle.map do |property|
86
+ type = native_type(property.type)
87
+ {
88
+ class_name: camelize(property.property_name),
89
+ property_name: constantize(property.property_name),
90
+ type: type,
91
+ is_special_property: is_special_property?(property.type),
92
+ destinations: property.destinations.map { |p| constantize(p) },
93
+ }
94
+ end
95
+
96
+ template_from(PEOPLE_PROPERTIES_TEMPLATE).result(binding)
45
97
  end
46
98
  end
47
99
 
48
- def special_property_enums(enums)
100
+ def people_properties_enum(people_bundle, file_name)
49
101
  header_footer_wrapper do
50
- enums.map do |enum|
51
- body = "enum class #{enum.enum_name}(val key: String) {\n"
52
- body << enum.values.map { |vals| "\t#{vals.tr(' ', '_').upcase}(\"#{vals}\")"}.join(",\n")
53
- body << ";\n}"
54
- end.join("\n\n")
102
+ class_name = file_name
103
+
104
+ properties = people_bundle.map(&:property_name).map do |property_name|
105
+ {
106
+ name: constantize(property_name),
107
+ value: property_name,
108
+ }
109
+ end
110
+
111
+ template_from(PEOPLE_PROPERTIES_ENUM_TEMPLATE).result(binding)
55
112
  end
56
113
  end
57
114
 
58
- private
115
+ def special_property_enums(enums_bundle)
116
+ header_footer_wrapper do
117
+ enums = enums_bundle.map do |enum|
118
+ values = enum.values.map do |value|
119
+ {
120
+ name: constantize(value),
121
+ value: value,
122
+ }
123
+ end
59
124
 
60
- def imports_header(imports = [])
61
- return unless imports.length > 0
62
- imports.map { |ev| ev. gsub("packagename", @package_name) }
63
- .join("\n") + "\n\n"
125
+ {
126
+ class_name: enum.enum_name,
127
+ values: values,
128
+ }
129
+ end
130
+
131
+ template_from(SPECIAL_PROPERTY_ENUMS_TEMPLATE).result(binding)
132
+ end
64
133
  end
65
134
 
66
- def header_footer_wrapper(imports = [])
67
- <<-Kotlin
68
- package #{@package_name}
135
+ def destinations(bundle, file_name)
136
+ header_footer_wrapper do
137
+ class_name = file_name
69
138
 
70
- #{imports_header(imports)}/**
71
- * This file was automatically generated by evva: https://github.com/hole19/evva
72
- */
139
+ destinations = bundle.map { |d| constantize(d) }
73
140
 
74
- #{yield.gsub("\t", " ")}
75
- Kotlin
141
+ template_from(DESTINATIONS_TEMPLATE).result(binding)
142
+ end
76
143
  end
77
144
 
78
- def kotlin_function(event_data)
79
- function_name = 'track' + titleize(event_data.event_name)
80
- function_arguments = event_data.properties.map { |name, type| "#{name}: #{type}" }.join(', ')
81
- if !function_arguments.empty?
82
- props = json_props(event_data.properties)
83
- """\topen fun #{function_name}(#{function_arguments}) {
84
- #{props}
85
- \t\tmask.trackEvent(MixpanelEvent.#{event_data.event_name.upcase}, properties)
86
- \t}"""
145
+ private
87
146
 
88
- else
89
- """\topen fun #{function_name}() {
90
- \t\tmask.trackEvent(MixpanelEvent.#{event_data.event_name.upcase})
91
- \t}"""
92
- end
147
+ def header_footer_wrapper
148
+ package_name = @package_name
149
+
150
+ content = yield
151
+ .chop # trim trailing newlines created by sublime
152
+
153
+ template_from(BASE_TEMPLATE).result(binding).gsub("\t", TAB_SIZE)
93
154
  end
94
155
 
95
- def json_props(properties)
96
- split_properties =
97
- properties
98
- .map do |name, type|
99
- if special_property?(type)
100
- if optional_property?(type)
101
- "#{name}?.let { put(\"#{name}\", it.key) }"
102
- else
103
- "put(\"#{name}\", #{name}.key)"
104
- end
105
- else
106
- if optional_property?(type)
107
- "#{name}?.let { put(\"#{name}\", it) }"
108
- else
109
- "put(\"#{name}\", #{name})"
110
- end
111
- end
112
- end
113
- .map { |line| "\t\t\t#{line}" }
114
- .join("\n")
156
+ def template_from(path)
157
+ file = File.read(path)
115
158
 
116
- "\t\tval properties = JSONObject().apply {\n#{split_properties}\n\t\t}"
159
+ # - 2nd argument (nil) changes nothing
160
+ # - 3rd argument activates trim mode using "-" so that you can decide to
161
+ # not include a line (useful on loops and if statements)
162
+ ERB.new(file, nil, '-')
117
163
  end
118
164
 
119
- def special_property?(type)
120
- !NATIVE_TYPES.include?(type.chomp('?'))
165
+ # extracted from Rails' ActiveSupport
166
+ def camelize(string, uppercase_first_letter = true)
167
+ string = string.to_s
168
+ if uppercase_first_letter
169
+ string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
170
+ else
171
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
172
+ end
173
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
121
174
  end
122
175
 
123
- def optional_property?(type)
124
- type.include?('?')
176
+ def constantize(string)
177
+ string.tr(' ', '_').upcase
125
178
  end
126
179
 
127
- def titleize(str)
128
- str.split('_').collect(&:capitalize).join
180
+ def native_type(type)
181
+ type
182
+ .gsub('Date','String')
183
+ end
184
+
185
+ def is_special_property?(type)
186
+ !NATIVE_TYPES.include?(type.chomp('?'))
129
187
  end
130
188
  end
131
189
  end
data/lib/evva/config.rb CHANGED
@@ -31,18 +31,26 @@ module Evva
31
31
  @hash[:event_file_name]
32
32
  end
33
33
 
34
+ def event_enum_file_name
35
+ @hash[:event_enum_file_name]
36
+ end
37
+
34
38
  def people_file_name
35
39
  @hash[:people_file_name]
36
40
  end
37
41
 
38
- def event_enum_file_name
39
- @hash[:event_enum_file_name]
42
+ def people_enum_file_name
43
+ @hash[:people_enum_file_name]
40
44
  end
41
45
 
42
46
  def special_enum_file_name
43
47
  @hash[:special_enum_file_name]
44
48
  end
45
49
 
50
+ def destinations_file_name
51
+ @hash[:destinations_file_name]
52
+ end
53
+
46
54
  def package_name
47
55
  @hash[:package_name]
48
56
  end
@@ -58,6 +66,8 @@ module Evva
58
66
  event_file_name: { type: String },
59
67
  event_enum_file_name: { type: String },
60
68
  people_file_name: { type: String },
69
+ people_enum_file_name: { type: String },
70
+ destinations_file_name: { type: String },
61
71
  package_name: { type: String }
62
72
  }
63
73
  }.freeze
@@ -3,6 +3,17 @@ require 'csv'
3
3
 
4
4
  module Evva
5
5
  class GoogleSheet
6
+ EVENT_NAME = 'Event Name'
7
+ EVENT_PROPERTIES = 'Event Properties'
8
+ EVENT_DESTINATION = 'Event Destination'
9
+
10
+ PROPERTY_NAME = 'Property Name'
11
+ PROPERTY_TYPE = 'Property Type'
12
+ PROPERTY_DESTINATION = 'Property Destination'
13
+
14
+ ENUM_NAME = 'Enum Name'
15
+ ENUM_VALUES = 'Possible Values'
16
+
6
17
  def initialize(events_url, people_properties_url, enum_classes_url)
7
18
  @events_url = events_url
8
19
  @people_properties_url = people_properties_url
@@ -10,41 +21,48 @@ module Evva
10
21
  end
11
22
 
12
23
  def events
13
- Logger.info("Downloading data from Google Sheet at #{@events_url}")
14
- csv = get_csv(@events_url)
15
-
16
- event_list = []
17
- csv.each do |row|
18
- event_name = row['Event Name']
19
- properties = hash_parser(row['Event Properties'])
20
- event_list << Evva::MixpanelEvent.new(event_name, properties)
24
+ @events_csv ||= begin
25
+ Logger.info("Downloading data from Google Sheet at #{@events_url}")
26
+ get_csv(@events_url)
27
+ end
28
+
29
+ @events ||= @events_csv.map do |row|
30
+ event_name = row[EVENT_NAME]
31
+ properties = hash_parser(row[EVENT_PROPERTIES])
32
+ destinations = row[EVENT_DESTINATION]&.split(',')
33
+ Evva::AnalyticsEvent.new(event_name, properties, destinations || [])
21
34
  end
22
- event_list
23
35
  end
24
36
 
25
37
  def people_properties
26
- Logger.info("Downloading data from Google Sheet at #{@people_properties_url}")
27
- csv = get_csv(@people_properties_url)
38
+ @people_properties_csv ||= begin
39
+ Logger.info("Downloading data from Google Sheet at #{@people_properties_url}")
40
+ get_csv(@people_properties_url)
41
+ end
28
42
 
29
- people_list = []
30
- csv.each do |row|
31
- value = row['Property Name']
32
- people_list << value
43
+ @people_properties ||= @people_properties_csv.map do |row|
44
+ property_name = row[PROPERTY_NAME]
45
+ property_type = row[PROPERTY_TYPE]
46
+ destinations = row[PROPERTY_DESTINATION]&.split(',')
47
+ Evva::AnalyticsProperty.new(property_name, property_type, destinations || [])
33
48
  end
34
- people_list
35
49
  end
36
50
 
37
51
  def enum_classes
38
- Logger.info("Downloading data from Google Sheet at #{@enum_classes_url}")
39
- csv = get_csv(@enum_classes_url)
40
-
41
- enum_list = []
42
- csv.each do |row|
43
- enum_name = row['Enum Name']
44
- values = row['Possible Values'].split(',')
45
- enum_list << Evva::MixpanelEnum.new(enum_name, values)
52
+ @enum_classes_csv ||= begin
53
+ Logger.info("Downloading data from Google Sheet at #{@enum_classes_url}")
54
+ get_csv(@enum_classes_url)
55
+ end
56
+
57
+ @enum_classes ||= @enum_classes_csv.map do |row|
58
+ enum_name = row[ENUM_NAME]
59
+ values = row[ENUM_VALUES].split(',')
60
+ Evva::AnalyticsEnum.new(enum_name, values)
46
61
  end
47
- enum_list
62
+ end
63
+
64
+ def destinations
65
+ @destinations ||= events.map(&:destinations).flatten.uniq
48
66
  end
49
67
 
50
68
  private