simplejson2csv 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2bec8ce4de7bfac9fd559c12bb1480c2032b5c8
4
+ data.tar.gz: 8862c30b2907af08dfd04f67c29b5da2c7dc5087
5
+ SHA512:
6
+ metadata.gz: f4d908d6d9d0ac0fa833d180c998904a8859ad038055dadc7fccc72ab97478422314ea2ef7fc6c91865945b20ee42adfc4d082002efd58281f917970dd591a92
7
+ data.tar.gz: aacc83fed651605a65945bcb747793da5755306650ad647059a8c5fbc02c5117877aecd76f3c3805dc3d589ae0b40f7c164936e58c7eb069286791cea56948e3
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,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,171 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simplejson2csv (0.1.0)
5
+ thor (~> 0.20.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.1.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ addressable (2.3.8)
16
+ aruba (0.14.3)
17
+ childprocess (~> 0.8.0)
18
+ contracts (~> 0.9)
19
+ cucumber (>= 1.3.19)
20
+ ffi (~> 1.9.10)
21
+ rspec-expectations (>= 2.99)
22
+ thor (~> 0.19)
23
+ ast (2.3.0)
24
+ awesome_print (1.8.0)
25
+ backports (3.11.0)
26
+ builder (3.2.3)
27
+ byebug (9.1.0)
28
+ childprocess (0.8.0)
29
+ ffi (~> 1.0, >= 1.0.11)
30
+ coderay (1.1.2)
31
+ concurrent-ruby (1.0.5)
32
+ contracts (0.16.0)
33
+ cucumber (3.1.0)
34
+ builder (>= 2.1.2)
35
+ cucumber-core (~> 3.1.0)
36
+ cucumber-expressions (~> 5.0.4)
37
+ cucumber-wire (~> 0.0.1)
38
+ diff-lcs (~> 1.3)
39
+ gherkin (~> 5.0)
40
+ multi_json (>= 1.7.5, < 2.0)
41
+ multi_test (>= 0.1.2)
42
+ cucumber-core (3.1.0)
43
+ backports (>= 3.8.0)
44
+ cucumber-tag_expressions (~> 1.1.0)
45
+ gherkin (>= 5.0.0)
46
+ cucumber-expressions (5.0.7)
47
+ cucumber-tag_expressions (1.1.1)
48
+ cucumber-wire (0.0.1)
49
+ diff-lcs (1.3)
50
+ docile (1.1.5)
51
+ factory_bot (4.8.2)
52
+ activesupport (>= 3.0.0)
53
+ faraday (0.9.2)
54
+ multipart-post (>= 1.2, < 3)
55
+ ffi (1.9.18)
56
+ flay (2.4.0)
57
+ ruby_parser (~> 3.0)
58
+ sexp_processor (~> 4.0)
59
+ gherkin (5.0.0)
60
+ grit (2.5.0)
61
+ diff-lcs (~> 1.1)
62
+ mime-types (~> 1.15)
63
+ posix-spawn (~> 0.3.6)
64
+ i18n (0.9.1)
65
+ concurrent-ruby (~> 1.0)
66
+ json (2.1.0)
67
+ method_source (0.9.0)
68
+ mime-types (1.25.1)
69
+ minitest (5.11.1)
70
+ multi_json (1.13.1)
71
+ multi_test (0.1.2)
72
+ multipart-post (2.0.0)
73
+ octokit (2.7.2)
74
+ sawyer (~> 0.5.2)
75
+ parser (2.4.0.2)
76
+ ast (~> 2.3)
77
+ posix-spawn (0.3.13)
78
+ powerpack (0.0.9)
79
+ pronto (0.2.6)
80
+ grit (~> 2.5, >= 2.5.0)
81
+ octokit (~> 2.7, >= 2.7.1)
82
+ rugged (>= 0.19.0, <= 0.20.0)
83
+ thor (~> 0.19, >= 0.19.1)
84
+ pronto-flay (0.2.0)
85
+ flay (~> 2.4.0)
86
+ pronto (~> 0.2.0)
87
+ pronto-reek (0.2.1)
88
+ pronto (~> 0.2.0)
89
+ reek (~> 1.3.6)
90
+ pronto-rubocop (0.2.1)
91
+ pronto (~> 0.2.0)
92
+ rubocop (~> 0.16.0)
93
+ pry (0.11.3)
94
+ coderay (~> 1.1.0)
95
+ method_source (~> 0.9.0)
96
+ pry-byebug (3.5.1)
97
+ byebug (~> 9.1)
98
+ pry (~> 0.10)
99
+ pry-meta (0.0.10)
100
+ awesome_print
101
+ pry
102
+ pry-byebug
103
+ pry-remote
104
+ pry-remote (0.1.8)
105
+ pry (~> 0.9)
106
+ slop (~> 3.0)
107
+ rainbow (2.2.2)
108
+ rake
109
+ rake (10.5.0)
110
+ reek (1.3.8)
111
+ rainbow (>= 1.99, < 3.0)
112
+ ruby2ruby (>= 2.0.8, < 3.0)
113
+ ruby_parser (~> 3.3)
114
+ sexp_processor
115
+ rspec (3.7.0)
116
+ rspec-core (~> 3.7.0)
117
+ rspec-expectations (~> 3.7.0)
118
+ rspec-mocks (~> 3.7.0)
119
+ rspec-core (3.7.1)
120
+ rspec-support (~> 3.7.0)
121
+ rspec-expectations (3.7.0)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.7.0)
124
+ rspec-mocks (3.7.0)
125
+ diff-lcs (>= 1.2.0, < 2.0)
126
+ rspec-support (~> 3.7.0)
127
+ rspec-support (3.7.0)
128
+ rubocop (0.16.0)
129
+ parser (~> 2.1)
130
+ powerpack (~> 0.0.6)
131
+ rainbow (>= 1.1.4)
132
+ ruby2ruby (2.4.0)
133
+ ruby_parser (~> 3.1)
134
+ sexp_processor (~> 4.6)
135
+ ruby_parser (3.10.1)
136
+ sexp_processor (~> 4.9)
137
+ rugged (0.19.0)
138
+ sawyer (0.5.5)
139
+ addressable (~> 2.3.5)
140
+ faraday (~> 0.8, < 0.10)
141
+ sexp_processor (4.10.0)
142
+ simplecov (0.15.1)
143
+ docile (~> 1.1.0)
144
+ json (>= 1.8, < 3)
145
+ simplecov-html (~> 0.10.0)
146
+ simplecov-html (0.10.2)
147
+ slop (3.6.0)
148
+ thor (0.20.0)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.4)
151
+ thread_safe (~> 0.1)
152
+
153
+ PLATFORMS
154
+ ruby
155
+
156
+ DEPENDENCIES
157
+ aruba (~> 0.14)
158
+ bundler (~> 1.16)
159
+ factory_bot (~> 4.8)
160
+ pronto (~> 0.2)
161
+ pronto-flay (~> 0.2)
162
+ pronto-reek (~> 0.2)
163
+ pronto-rubocop (~> 0.2)
164
+ pry-meta (~> 0.0)
165
+ rake (~> 10.0)
166
+ rspec (~> 3.0)
167
+ simplecov (~> 0.15)
168
+ simplejson2csv!
169
+
170
+ BUNDLED WITH
171
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Simplejson2csv
2
+
3
+ This command-line-tool was designed to EASILY convert JSON to CSV.
4
+ You can set which fields (keys) you want to output!
5
+ You can choose which separator you want!
6
+
7
+ Purpose:
8
+ I did a grep in a bunch of log files with different JSON's formats. So I needed to parse then and choose just a few fields that were relevant.
9
+ I wrote a simple ruby file to do this job and I thought:
10
+ "Hmm, why would I publish this on RubyGems?...
11
+ A: Why not?"
12
+
13
+ ## Installation
14
+
15
+ Just install it:
16
+
17
+ $ gem install simplejson2csv
18
+
19
+ ## Usage
20
+
21
+ Help:
22
+
23
+ $ simplejson2csv help convert
24
+
25
+ Convert:
26
+
27
+ $ simplejson2csv convert --json=tmp/sample.json --csv=tmp/sample-output.csv
28
+ --fields="foo bar" --separator="|"
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ ## Contributing
35
+
36
+ [Bug reports](https://github.com/walbinjr/simplejson2csv/issues) and [pull requests](https://github.com/walbinjr/simplejson2csv/pulls) are welcome on GitHub at https://github.com/walbinjr/simplejson2csv.
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 "simplejson2csv"
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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'simplejson2csv'
3
+ Simplejson2csv::CLI.start(ARGV)
@@ -0,0 +1,6 @@
1
+ require "simplejson2csv/version"
2
+ require "simplejson2csv/cli"
3
+ require "simplejson2csv/converter"
4
+
5
+ module Simplejson2csv
6
+ end
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+
3
+ module Simplejson2csv
4
+ class CLI < Thor
5
+ desc "convert", "Convert JSON to CSV filtering <fields> with <separator>."
6
+ long_desc <<-LONGDESC
7
+ Convert JSON to CSV filtering <fields> with <separator>.
8
+ \x5
9
+ \x5 --csv, <csv_file> location output.
10
+ \x5 --json, <json_file> location.
11
+ \x5 --fields, <fields> a space separated string (i.e.: "foo bar dump")
12
+ \x5 > IF using a custom separator, use the SAME separator.
13
+ \x5 --separator, <separator> (OPTIONAL) should be a custom separator
14
+ (i.e.: "|"").
15
+ \x5
16
+ \x5> EXAMPLE:
17
+ \x5> simplejson2csv convert --json=tmp/sample.json --csv=tmp/sample-output.csv
18
+ --fields="foo bar" --separator="|"
19
+ LONGDESC
20
+ option :json, :required => true, :type => :string, :banner => "<json_file>"
21
+ option :csv, :required => true, :type => :string, :banner => "<csv_file>"
22
+ option :fields, :required => true, :type => :string, :banner => "<fields>"
23
+ option :separator, :type => :string
24
+ def convert
25
+ Simplejson2csv::Converter.convert(options)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ require 'csv'
2
+ require 'json'
3
+
4
+ module Simplejson2csv
5
+ class Converter
6
+ class << self
7
+ attr_accessor :opts
8
+
9
+ def convert(opts={})
10
+ @opts = opts
11
+ save_to_csv
12
+ end
13
+
14
+ private
15
+
16
+ def generate_csv_from_json
17
+ json = JSON.parse(IO.read(opts[:json]))
18
+ json.map do |item|
19
+ fields.map do |field|
20
+ item[field]
21
+ end
22
+ end
23
+ rescue => error
24
+ raise error
25
+ end
26
+
27
+ def save_to_csv
28
+ CSV.open(opts[:csv], 'w', col_sep: separator) do |csv|
29
+ csv << fields
30
+ generate_csv_from_json.each do |row|
31
+ csv << row
32
+ end
33
+ end
34
+ end
35
+
36
+ def separator
37
+ opts[:separator] || ','
38
+ end
39
+
40
+ def fields
41
+ @fields ||= opts[:fields].split
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Simplejson2csv
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simplejson2csv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'simplejson2csv'
8
+ spec.version = Simplejson2csv::VERSION
9
+ spec.licenses = ['MIT']
10
+ spec.authors = ['Walter Bindilatti Junior']
11
+ spec.email = ['walbinjr@gmail.com']
12
+
13
+ spec.summary = %q{A command-line tool to EASILY convert JSON to CSV.}
14
+ spec.description = %q{Use a given JSON and fields names to generate a CSV.}
15
+ spec.homepage = 'https://github.com/walbinjr/simplejson2csv'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.16'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'aruba', '~> 0.14'
28
+ spec.add_development_dependency 'pry-meta', '~> 0.0'
29
+ spec.add_development_dependency 'simplecov', '~> 0.15'
30
+ spec.add_development_dependency 'factory_bot', '~> 4.8'
31
+ spec.add_development_dependency 'pronto', '~> 0.2'
32
+ spec.add_development_dependency 'pronto-rubocop', '~> 0.2'
33
+ spec.add_development_dependency 'pronto-flay', '~> 0.2'
34
+ spec.add_development_dependency 'pronto-reek', '~> 0.2'
35
+
36
+ spec.add_dependency 'thor', '~> 0.20.0'
37
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplejson2csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Walter Bindilatti Junior
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-meta
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.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.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_bot
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pronto
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pronto-rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pronto-flay
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pronto-reek
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.2'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.2'
167
+ - !ruby/object:Gem::Dependency
168
+ name: thor
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.20.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.20.0
181
+ description: Use a given JSON and fields names to generate a CSV.
182
+ email:
183
+ - walbinjr@gmail.com
184
+ executables:
185
+ - simplejson2csv
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - README.md
194
+ - Rakefile
195
+ - bin/console
196
+ - bin/setup
197
+ - exe/simplejson2csv
198
+ - lib/simplejson2csv.rb
199
+ - lib/simplejson2csv/cli.rb
200
+ - lib/simplejson2csv/converter.rb
201
+ - lib/simplejson2csv/version.rb
202
+ - simplejson2csv.gemspec
203
+ homepage: https://github.com/walbinjr/simplejson2csv
204
+ licenses:
205
+ - MIT
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubyforge_project:
223
+ rubygems_version: 2.6.11
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: A command-line tool to EASILY convert JSON to CSV.
227
+ test_files: []