sheetsy 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ff1fa3dcb8a6e0cfcb6060090fb2f0579f0135733c91f7b27cd58119db32e96
4
- data.tar.gz: 206236d9ace11c5c51a31e806a69caee1bd5fce62c36afdacc99eb9e78d7d6e9
3
+ metadata.gz: 5187487347d0e1505b9e40889c488ab8341fb55d866d6af96487addcb0a60150
4
+ data.tar.gz: 863582071eb4b16b551b034ea0ceb5b380603fff767f2ac4314a55c3d3789d95
5
5
  SHA512:
6
- metadata.gz: 2c51cbc55f00bd062c5ad5ae12024e5ce67240f117fd11fcbd30c58128506ff09dd5c63b6ffd8c663e6734dbbeaae3206123de6978871e95a22cbe0dabe7fc61
7
- data.tar.gz: dabe8bbe400354efbffe1d1344a7f31aecb4d3596d31f6913ba99356d04dbc6762568153a6e79eb521fcafd5f7e88c023304df21a76acf0d1c447d60a31233a2
6
+ metadata.gz: be8be3a1ae1e007f319cc65b4f400e95a8acba69715ea17b8844693799d95bce5b95791f5db51bcc2fb9a6e2a98269b626c5c11218279d7bf929612171de2ed3
7
+ data.tar.gz: 399dea79e08ecdbee1ee49268511a0e2ab1e3a4228706ec59c2db8f520b2c393557710f4df452ffd94f927389b5fd9414bca6556832629bcc3b8a68205406c79
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ gem "rspec", "~> 3.0"
12
12
  gem "rubocop", "~> 1.21"
13
13
 
14
14
  gem "roo"
15
+ gem "ruby-progressbar"
15
16
  gem "thor"
16
17
 
17
18
  group :development, :test do
@@ -20,4 +21,4 @@ end
20
21
 
21
22
  group :development do
22
23
  gem "pry"
23
- end
24
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sheetsy (0.1.0)
4
+ sheetsy (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -75,6 +75,7 @@ DEPENDENCIES
75
75
  roo
76
76
  rspec (~> 3.0)
77
77
  rubocop (~> 1.21)
78
+ ruby-progressbar
78
79
  sheetsy!
79
80
  thor
80
81
 
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Sheetsy
2
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/sheetsy`. 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
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
- $> sheetsy convert
20
+ $ sheetsy convert
23
21
  ```
24
22
 
25
23
  To learn more about available options:
26
24
 
27
25
  ```bash
28
- $> sheetsy help convert
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 :override, type: :boolean, aliases: :o, default: false
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
- overwrite = if options[:overwrite]
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
@@ -2,68 +2,90 @@
2
2
 
3
3
  module Sheetsy
4
4
  class Converter
5
- attr_reader :source, :destination, :overwrite
5
+ attr_reader :source, :destination, :options
6
6
 
7
- def initialize(source, destination, overwrite = false)
7
+ def initialize(source, destination, options = {})
8
8
  @source = source
9
9
  @destination = destination
10
- @overwrite = overwrite
10
+ @options = options
11
11
  end
12
12
 
13
13
  def run
14
- files = Dir.glob(File.join(source, "**/*.{xls,xlsx,csv}"))
15
- puts "Files found: #{files.count}"
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 == true
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
- puts "Processing as CSV"
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
- puts "File #{output_file_path}"
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
- puts "Converted #{file} to #{output_file_path}\n\n"
62
+ debug "Converted #{file} to #{output_file_path}\n\n"
41
63
  end
42
64
 
43
65
  def process_excel(file)
44
- puts "Processing as Excel"
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
- puts "Sheet #{output_file_path}"
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
- puts "Converted #{file} to #{output_file_path}\n\n"
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
- puts "File: #{file}"
85
+ debug "File: #{file}"
64
86
 
65
87
  if file.include?("~$")
66
- puts "Skipping #{file}\n\n"
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
- puts "Unsupported file format: #{file}"
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
- puts "Skipping #{file}"
120
+ debug "Skipping #{file}"
99
121
  true
100
122
  end
101
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sheetsy
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/sheetsy.rb CHANGED
@@ -4,6 +4,7 @@ require "json"
4
4
  require "roo"
5
5
  require "csv"
6
6
  require "pry"
7
+ require "ruby-progressbar"
7
8
 
8
9
  require_relative "sheetsy/version"
9
10
  require_relative "sheetsy/converter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheetsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily convert CSV and Excel sheets to JSON
14
14
  email: