module Tagger class CLI < Thor desc "generate", "an AnlayticsEvent file" option :platform, required: true option :out, required: true def generate(url) puts "Generate AnalyticsEvent.#{options[:platform] == 'ios' ? 'swift' : 'kotlin'}" # Download as CSV downloader = Tagger::Downloader.new(url) downloader.download_and_write() # Parse CSV raw_file = CSV.read("tmp/raw.csv", headers: true) events = raw_file.map do |row| event_name = row[1] if event_name.nil? nil else param_names = row.headers[(3)..-1] param_values = row[(3)..-1] Tagger::Event.new(event_name, param_values.compact.size == 0 ? nil : Hash[param_names.zip param_values]) end end.compact generator = Tagger::Generator.new(events, options[:platform].to_sym) generator.generate(options[:out]) end end end