ai_tagger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f318e31a5678ca5d6fac3418fb722c39da89f54f
4
+ data.tar.gz: 26b74a87a4dd09a1b678df549a056c5bbbb4f0b0
5
+ SHA512:
6
+ metadata.gz: 5aaa77bf6b1e32bda7dde198ed0a54633cbcddaf483448674b12dbc5e399bc0edf0482fbc7a125bf1fca0ba990f0b651a6b330aab7862743adf36e43cd7ae997
7
+ data.tar.gz: f16f6c36b1ef20083f7cb70df790e0036ea98ec374515ac4155a6ad1b3f74fd348a2758c100503f159f6e496a312c6e2f54c26dac7e2c9032df89751cd897884
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tagger.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ai_tagger (0.1.0)
5
+ activesupport (~> 5.2.3)
6
+ thor (~> 0.20.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.6.0)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ concurrent-ruby (1.1.5)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ docile (1.3.1)
23
+ hashdiff (0.3.9)
24
+ i18n (1.6.0)
25
+ concurrent-ruby (~> 1.0)
26
+ json (2.2.0)
27
+ minitest (5.11.3)
28
+ public_suffix (3.0.3)
29
+ rake (10.5.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ safe_yaml (1.0.5)
44
+ simplecov (0.16.1)
45
+ docile (~> 1.1)
46
+ json (>= 1.8, < 3)
47
+ simplecov-html (~> 0.10.0)
48
+ simplecov-html (0.10.2)
49
+ thor (0.20.3)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.5)
52
+ thread_safe (~> 0.1)
53
+ webmock (3.5.1)
54
+ addressable (>= 2.3.6)
55
+ crack (>= 0.3.2)
56
+ hashdiff
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ ai_tagger!
63
+ bundler (~> 2.0)
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+ simplecov (~> 0.16.1)
67
+ webmock (~> 3.5.1)
68
+
69
+ BUNDLED WITH
70
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Tagger
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tagger`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tagger'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tagger
22
+
23
+ ## Usage
24
+
25
+ Run `tagger generate SPREADSHEET_URL --platform ios --out OUTPUT_PATH`
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tagger.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tagger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/tagger ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tagger"
5
+
6
+ Tagger::CLI.start(ARGV)
@@ -0,0 +1,9 @@
1
+ sealed class AnalyticsEvent(val name: String, var dictionary: Map<String,String> = emptyMap()) {
2
+ <%- for @event in @events -%>
3
+ <%- if @event.params.nil? -%>
4
+ class <%= @event.name %> : AnalyticsEvent("<%= @event.name %>")
5
+ <%- else -%>
6
+ class <%= @event.name %> : AnalyticsEvent("<%= @event.name %>", <%= @event.params_for(:android) %>)
7
+ <%- end -%>
8
+ <%- end -%>
9
+ }
@@ -0,0 +1,27 @@
1
+ import Foundation
2
+
3
+ public enum AnalyticsEvent {
4
+ <%- for @event in @events -%>
5
+ case .<%= @event.name %>
6
+ <%- end -%>
7
+
8
+ public var name: String {
9
+ switch self {
10
+ <%- for @event in @events -%>
11
+ case .<%= @event.name %>: return "<%= @event.name %>"
12
+ <%- end -%>
13
+ }
14
+ }
15
+
16
+ public var params: [String:String]? {
17
+ switch self {
18
+ <%- for @event in @events -%>
19
+ <%- if @event.params.nil? -%>
20
+ case .<%= @event.name %>: return nil
21
+ <%- else -%>
22
+ case .<%= @event.name %>: return <%= @event.params_for(:ios) %>
23
+ <%- end -%>
24
+ <%- end -%>
25
+ }
26
+ }
27
+ }
data/lib/tagger/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Tagger
2
+ class CLI < Thor
3
+ desc "generate", "an AnlayticsEvent file"
4
+ option :platform, required: true
5
+ option :out, required: true
6
+ def generate(url)
7
+ puts "Generate AnalyticsEvent.#{options[:platform] == 'ios' ? 'swift' : 'kotlin'}"
8
+
9
+ # Download as CSV
10
+ downloader = Tagger::Downloader.new(url)
11
+ downloader.download_and_write()
12
+
13
+ # Parse CSV
14
+ raw_file = CSV.read("tmp/raw.csv", headers: true)
15
+ events = raw_file.map do |row|
16
+ event_name = row[1]
17
+ if event_name.nil?
18
+ nil
19
+ else
20
+ param_names = row.headers[(3)..-1]
21
+ param_values = row[(3)..-1]
22
+
23
+ Tagger::Event.new(event_name, param_values.compact.size == 0 ? nil : Hash[param_names.zip param_values])
24
+ end
25
+ end.compact
26
+
27
+ generator = Tagger::Generator.new(events, options[:platform].to_sym)
28
+ generator.generate(options[:out])
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module Tagger
2
+ class Downloader
3
+ attr_accessor :spreadsheet_url
4
+
5
+ def initialize(spreadsheet_url)
6
+ @spreadsheet_url = spreadsheet_url
7
+ end
8
+
9
+ def download_and_write
10
+ content = download()
11
+ write_to_file(content)
12
+ end
13
+
14
+ private
15
+
16
+ def download
17
+ open(@spreadsheet_url).read
18
+ end
19
+
20
+ def write_to_file(content)
21
+ File.write("tmp/raw.csv", content)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Tagger
2
+ class Event
3
+ attr_accessor :name, :params
4
+
5
+ def initialize(name, params = nil)
6
+ @name = name
7
+ @params = params
8
+ end
9
+
10
+ def params_for(platform)
11
+ case platform
12
+ when :ios
13
+ map_content = params.map do |key, val|
14
+ '"' + key.to_s + '"' + ": " + '"' + val.to_s + '"'
15
+ end.join(", ")
16
+ "[" + map_content + "]"
17
+ when :android
18
+ map_content = params.map do |key, val|
19
+ '"' + key.to_s + '"' + " to " + '"' + val.to_s + '"'
20
+ end.join(", ")
21
+ "mapOf(" + map_content + ")"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ module Tagger
2
+ class Generator
3
+ attr_accessor :events, :platform
4
+
5
+ def initialize(events, platform)
6
+ @events = events
7
+ @platform = platform
8
+ end
9
+
10
+ def generate(output_location)
11
+ File.write("#{output_location}/#{output_file_name}", output)
12
+ end
13
+
14
+ private
15
+
16
+ def template
17
+ File.open(template_file, "r").read
18
+ end
19
+
20
+ def output_file_name
21
+ case @platform
22
+ when :ios
23
+ "AnalyticsEvent.swift"
24
+ when :android
25
+ "AnalyticsEvent.kt"
26
+ end
27
+ end
28
+
29
+ def template_file
30
+ case @platform
31
+ when :ios
32
+ "data/templates/AnalyticsEvent.swift.erb"
33
+ when :android
34
+ "data/templates/AnalyticsEvent.kt.erb"
35
+ end
36
+ end
37
+
38
+ def renderer
39
+ ERB.new(template, nil, '-')
40
+ end
41
+
42
+ def output
43
+ renderer.result(binding)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Tagger
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tagger.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "active_support"
2
+ require "open-uri"
3
+ require "csv"
4
+ require "erb"
5
+ require "thor"
6
+
7
+ require "tagger/version"
8
+ require "tagger/event"
9
+ require "tagger/generator"
10
+ require "tagger/downloader"
11
+ require "tagger/cli"
12
+
13
+ module Tagger
14
+ class Error < StandardError; end
15
+ end
data/tagger.gemspec ADDED
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tagger/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ai_tagger"
8
+ spec.version = Tagger::VERSION
9
+ spec.authors = ["Dunya Kirkali"]
10
+ spec.email = ["dunyakirkali@gmail.com"]
11
+
12
+ spec.summary = %q{Generate AnalyticsEvent classes in Kotlin and Swift}
13
+ spec.description = %q{This gem generates AnalyticsEvent classes from a Google Doc}
14
+ spec.homepage = "https://github.com/abnamrocoesd/tagger"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
23
+ spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency "activesupport", "~> 5.2.3"
39
+ spec.add_dependency "thor", "~> 0.20.3"
40
+
41
+ spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "simplecov", "~> 0.16.1"
45
+ spec.add_development_dependency "webmock", "~> 3.5.1"
46
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ai_tagger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dunya Kirkali
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.20.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.20.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.16.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.16.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.5.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.5.1
111
+ description: This gem generates AnalyticsEvent classes from a Google Doc
112
+ email:
113
+ - dunyakirkali@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".DS_Store"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - bin/tagger
129
+ - data/templates/AnalyticsEvent.kt.erb
130
+ - data/templates/AnalyticsEvent.swift.erb
131
+ - lib/tagger.rb
132
+ - lib/tagger/cli.rb
133
+ - lib/tagger/downloader.rb
134
+ - lib/tagger/event.rb
135
+ - lib/tagger/generator.rb
136
+ - lib/tagger/version.rb
137
+ - tagger.gemspec
138
+ homepage: https://github.com/abnamrocoesd/tagger
139
+ licenses: []
140
+ metadata:
141
+ allowed_push_host: https://rubygems.org
142
+ homepage_uri: https://github.com/abnamrocoesd/tagger
143
+ source_code_uri: 'TODO: Put your gem''s public repo URL here.'
144
+ changelog_uri: 'TODO: Put your gem''s CHANGELOG.md URL here.'
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.6.14
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Generate AnalyticsEvent classes in Kotlin and Swift
165
+ test_files: []