sheetsy 0.1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -10
- data/Gemfile.lock +32 -33
- data/README.md +3 -5
- data/lib/sheetsy/cli.rb +3 -10
- data/lib/sheetsy/converter.rb +38 -16
- data/lib/sheetsy/version.rb +1 -1
- data/lib/sheetsy.rb +1 -0
- metadata +88 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1657d9d17ecb875a0ee44347fa799432cfe45d69c96cf4fdde1ddd790b66bfb
|
4
|
+
data.tar.gz: 817112d9e9c2165564690570c1c32edb8588366776e817484516a6b000a29b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae345e0b375497fa4d5480bbbb2c2979da0d825c97fbba88e1209d094c7e5ef3eec1f2e90a3166c0dfe99bffad112d5fe76fa2cf1c1992db8c9be7bd164fd0d
|
7
|
+
data.tar.gz: 4d6ce7739558090453106d37cb1a17e114ca7f4ad3b5ffa2f645668df557c3ee6be90a55fcc4b10502a66386b27a299ec426c6e9aca6ed01773fa4bf26e086c8
|
data/Gemfile
CHANGED
@@ -5,19 +5,10 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in sheetsy.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
gem "rspec", "~> 3.0"
|
11
|
-
|
12
|
-
gem "rubocop", "~> 1.21"
|
13
|
-
|
14
|
-
gem "roo"
|
15
|
-
gem "thor"
|
16
|
-
|
17
8
|
group :development, :test do
|
18
9
|
gem "pd_ruby"
|
19
10
|
end
|
20
11
|
|
21
12
|
group :development do
|
22
13
|
gem "pry"
|
23
|
-
end
|
14
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sheetsy (
|
4
|
+
sheetsy (1.1.0)
|
5
|
+
rake (~> 13.0)
|
6
|
+
roo
|
7
|
+
rspec (~> 3.0)
|
8
|
+
rubocop (~> 1.21)
|
9
|
+
ruby-progressbar
|
10
|
+
thor
|
5
11
|
|
6
12
|
GEM
|
7
13
|
remote: https://rubygems.org/
|
8
14
|
specs:
|
9
15
|
ast (2.4.2)
|
10
|
-
base64 (0.1.1)
|
11
16
|
coderay (1.1.3)
|
12
17
|
colorize (1.1.0)
|
13
|
-
diff-lcs (1.5.
|
14
|
-
json (2.
|
18
|
+
diff-lcs (1.5.1)
|
19
|
+
json (2.7.1)
|
15
20
|
language_server-protocol (3.17.0.3)
|
16
21
|
method_source (1.0.0)
|
17
|
-
nokogiri (1.
|
22
|
+
nokogiri (1.16.2-arm64-darwin)
|
18
23
|
racc (~> 1.4)
|
19
|
-
parallel (1.
|
20
|
-
parser (3.
|
24
|
+
parallel (1.24.0)
|
25
|
+
parser (3.3.0.5)
|
21
26
|
ast (~> 2.4.1)
|
22
27
|
racc
|
23
28
|
pd_ruby (0.2.3)
|
@@ -25,44 +30,43 @@ GEM
|
|
25
30
|
pry (0.14.2)
|
26
31
|
coderay (~> 1.1)
|
27
32
|
method_source (~> 1.0)
|
28
|
-
racc (1.7.
|
33
|
+
racc (1.7.3)
|
29
34
|
rainbow (3.1.1)
|
30
|
-
rake (13.0
|
31
|
-
regexp_parser (2.
|
35
|
+
rake (13.1.0)
|
36
|
+
regexp_parser (2.9.0)
|
32
37
|
rexml (3.2.6)
|
33
|
-
roo (2.10.
|
38
|
+
roo (2.10.1)
|
34
39
|
nokogiri (~> 1)
|
35
40
|
rubyzip (>= 1.3.0, < 3.0.0)
|
36
|
-
rspec (3.
|
37
|
-
rspec-core (~> 3.
|
38
|
-
rspec-expectations (~> 3.
|
39
|
-
rspec-mocks (~> 3.
|
40
|
-
rspec-core (3.
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-expectations (3.
|
41
|
+
rspec (3.13.0)
|
42
|
+
rspec-core (~> 3.13.0)
|
43
|
+
rspec-expectations (~> 3.13.0)
|
44
|
+
rspec-mocks (~> 3.13.0)
|
45
|
+
rspec-core (3.13.0)
|
46
|
+
rspec-support (~> 3.13.0)
|
47
|
+
rspec-expectations (3.13.0)
|
43
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-mocks (3.
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-mocks (3.13.0)
|
46
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-support (3.
|
49
|
-
rubocop (1.
|
50
|
-
base64 (~> 0.1.1)
|
52
|
+
rspec-support (~> 3.13.0)
|
53
|
+
rspec-support (3.13.0)
|
54
|
+
rubocop (1.60.2)
|
51
55
|
json (~> 2.3)
|
52
56
|
language_server-protocol (>= 3.17.0)
|
53
57
|
parallel (~> 1.10)
|
54
|
-
parser (>= 3.
|
58
|
+
parser (>= 3.3.0.2)
|
55
59
|
rainbow (>= 2.2.2, < 4.0)
|
56
60
|
regexp_parser (>= 1.8, < 3.0)
|
57
61
|
rexml (>= 3.2.5, < 4.0)
|
58
|
-
rubocop-ast (>= 1.
|
62
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
59
63
|
ruby-progressbar (~> 1.7)
|
60
64
|
unicode-display_width (>= 2.4.0, < 3.0)
|
61
|
-
rubocop-ast (1.
|
65
|
+
rubocop-ast (1.30.0)
|
62
66
|
parser (>= 3.2.1.0)
|
63
67
|
ruby-progressbar (1.13.0)
|
64
68
|
rubyzip (2.3.2)
|
65
|
-
thor (1.
|
69
|
+
thor (1.3.0)
|
66
70
|
unicode-display_width (2.5.0)
|
67
71
|
|
68
72
|
PLATFORMS
|
@@ -71,12 +75,7 @@ PLATFORMS
|
|
71
75
|
DEPENDENCIES
|
72
76
|
pd_ruby
|
73
77
|
pry
|
74
|
-
rake (~> 13.0)
|
75
|
-
roo
|
76
|
-
rspec (~> 3.0)
|
77
|
-
rubocop (~> 1.21)
|
78
78
|
sheetsy!
|
79
|
-
thor
|
80
79
|
|
81
80
|
BUNDLED WITH
|
82
81
|
2.3.26
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Sheetsy
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Sheetsy is a simple ruby utility to recursively convert all CSV and Excel-based sheets to individual JSON files.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -19,13 +17,13 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
19
17
|
To get started, run the following command from bash:
|
20
18
|
|
21
19
|
```bash
|
22
|
-
|
20
|
+
$ sheetsy convert
|
23
21
|
```
|
24
22
|
|
25
23
|
To learn more about available options:
|
26
24
|
|
27
25
|
```bash
|
28
|
-
|
26
|
+
$ sheetsy help convert
|
29
27
|
```
|
30
28
|
|
31
29
|
## Development
|
data/lib/sheetsy/cli.rb
CHANGED
@@ -7,7 +7,8 @@ module Sheetsy
|
|
7
7
|
desc "convert", "Convert sheets to JSON"
|
8
8
|
option :source, type: :string, aliases: :s
|
9
9
|
option :destination, type: :string, aliases: :d
|
10
|
-
option :
|
10
|
+
option :overwrite, type: :boolean, aliases: :o, default: false
|
11
|
+
option :debug, type: :boolean, default: false
|
11
12
|
def convert
|
12
13
|
source = if options[:source]
|
13
14
|
options[:source]
|
@@ -27,15 +28,7 @@ module Sheetsy
|
|
27
28
|
get_input("Output Directory", File.join(*default_source_folders, default_output_folder))
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
options[:overwrite]
|
32
|
-
elsif ENV.key?("OVERWRITE")
|
33
|
-
ENV.fetch("OVERWRITE")&.downcase == "y"
|
34
|
-
else
|
35
|
-
get_input("Overwrite Y/n? (n): ", "n").downcase == "y"
|
36
|
-
end
|
37
|
-
|
38
|
-
Sheetsy::Converter.new(source, destination, overwrite).run
|
31
|
+
Sheetsy::Converter.new(source, destination, options).run
|
39
32
|
end
|
40
33
|
|
41
34
|
private
|
data/lib/sheetsy/converter.rb
CHANGED
@@ -2,68 +2,90 @@
|
|
2
2
|
|
3
3
|
module Sheetsy
|
4
4
|
class Converter
|
5
|
-
attr_reader :source, :destination, :
|
5
|
+
attr_reader :source, :destination, :options
|
6
6
|
|
7
|
-
def initialize(source, destination,
|
7
|
+
def initialize(source, destination, options = {})
|
8
8
|
@source = source
|
9
9
|
@destination = destination
|
10
|
-
@
|
10
|
+
@options = options
|
11
11
|
end
|
12
12
|
|
13
13
|
def run
|
14
|
-
|
15
|
-
|
14
|
+
debug "Files found: #{files.count}"
|
15
|
+
|
16
|
+
progress_bar.progress = 0
|
16
17
|
|
17
18
|
FileUtils.mkdir_p(destination) unless File.directory?(destination)
|
18
19
|
|
19
20
|
files.each do |file|
|
20
21
|
process_file(file)
|
22
|
+
progress_bar.increment
|
21
23
|
end
|
24
|
+
|
25
|
+
puts "Conversion complete."
|
22
26
|
end
|
23
27
|
|
24
28
|
def overwrite?
|
25
|
-
overwrite
|
29
|
+
@overwrite ||= options[:overwrite]
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug?
|
33
|
+
@debug ||= options[:debug]
|
26
34
|
end
|
27
35
|
|
28
36
|
private
|
29
37
|
|
38
|
+
def files
|
39
|
+
@files ||= Dir.glob(File.join(source, "**/*.{xls,xlsx,csv}"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def progress_bar
|
43
|
+
@progress_bar ||= ProgressBar.create(title: "Files", total: files.count)
|
44
|
+
end
|
45
|
+
|
46
|
+
def debug(str)
|
47
|
+
return unless debug?
|
48
|
+
|
49
|
+
progress_bar.log str
|
50
|
+
end
|
51
|
+
|
30
52
|
def process_csv(file)
|
31
|
-
|
53
|
+
debug "Processing as CSV"
|
32
54
|
|
33
55
|
output_file_path = File.join(destination, "#{nameify(file)}.json")
|
34
56
|
return if skip?(output_file_path)
|
35
57
|
|
36
|
-
|
58
|
+
debug "File #{output_file_path}"
|
37
59
|
|
38
60
|
data = CSV.read(file, headers: true).map(&:to_h)
|
39
61
|
write_json(output_file_path, data)
|
40
|
-
|
62
|
+
debug "Converted #{file} to #{output_file_path}\n\n"
|
41
63
|
end
|
42
64
|
|
43
65
|
def process_excel(file)
|
44
|
-
|
66
|
+
debug "Processing as Excel"
|
45
67
|
excel = Roo::Spreadsheet.open(file)
|
46
68
|
|
47
69
|
excel.sheets.each do |sheet_name|
|
48
70
|
output_file_path = File.join(destination, "#{nameify(file)}__sheet__#{nameify(sheet_name)}.json")
|
49
71
|
return if skip?(output_file_path)
|
50
72
|
|
51
|
-
|
73
|
+
debug "Sheet #{output_file_path}"
|
52
74
|
|
53
75
|
sheet = excel.sheet(sheet_name)
|
54
76
|
header_row = (output_file_path.include?("Synergy_Output__") ? 2 : 1)
|
55
77
|
header = sheet.row(header_row)
|
56
78
|
data = ((header_row + 1)..sheet.last_row).map { |i| Hash[header.zip(sheet.row(i))] }
|
57
79
|
write_json(output_file_path, data)
|
58
|
-
|
80
|
+
debug "Converted #{file} to #{output_file_path}\n\n"
|
59
81
|
end
|
60
82
|
end
|
61
83
|
|
62
84
|
def process_file(file)
|
63
|
-
|
85
|
+
debug "File: #{file}"
|
64
86
|
|
65
87
|
if file.include?("~$")
|
66
|
-
|
88
|
+
debug "Skipping #{file}\n\n"
|
67
89
|
|
68
90
|
return
|
69
91
|
end
|
@@ -76,7 +98,7 @@ module Sheetsy
|
|
76
98
|
elsif [".xls", ".xlsx"].include?(extension)
|
77
99
|
process_excel(file)
|
78
100
|
else
|
79
|
-
|
101
|
+
debug "Unsupported file format: #{file}"
|
80
102
|
return
|
81
103
|
end
|
82
104
|
end
|
@@ -95,7 +117,7 @@ module Sheetsy
|
|
95
117
|
return false if overwrite?
|
96
118
|
return false unless File.exist?(file)
|
97
119
|
|
98
|
-
|
120
|
+
debug "Skipping #{file}"
|
99
121
|
true
|
100
122
|
end
|
101
123
|
end
|
data/lib/sheetsy/version.rb
CHANGED
data/lib/sheetsy.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheetsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2024-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.21'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.21'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: roo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-progressbar
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
13
97
|
description: Easily convert CSV and Excel sheets to JSON
|
14
98
|
email:
|
15
99
|
- sheetsy@rwj.dev
|
@@ -56,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
140
|
- !ruby/object:Gem::Version
|
57
141
|
version: '0'
|
58
142
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
143
|
+
rubygems_version: 3.4.22
|
60
144
|
signing_key:
|
61
145
|
specification_version: 4
|
62
146
|
summary: Easily convert CSV and Excel sheets to JSON
|