sheetsy 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sheetsy/cli.rb +15 -0
- data/lib/sheetsy/json_file.rb +23 -0
- data/lib/sheetsy/reader.rb +48 -0
- data/lib/sheetsy/version.rb +1 -1
- data/lib/sheetsy.rb +3 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e90c7665d0f2aed22d9e22fe98598c4e93a086cd4062594bc0ae7e2ca159cfbb
|
4
|
+
data.tar.gz: f9aaf7ffc9bac9bb91415a07c24144e56e841aa3d51d0562ae4b9b229f465ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae08fab3b426ee42757dcfb87df09cda5d6e5b5eb2ffa4abbba341b4feb1cf9669e967bea5cd4bb10c7e2b815c5949173959a34524a1df57f52f0cad67f45e4
|
7
|
+
data.tar.gz: 8d00f374dd99771a76091332ea2770cdda613729916ad8c55dc384879aef4d74f9e3961dc59a8db6616e0093e98b63e476931eed2c90b23e133d4de682f70ee8
|
data/Gemfile.lock
CHANGED
data/lib/sheetsy/cli.rb
CHANGED
@@ -31,6 +31,21 @@ module Sheetsy
|
|
31
31
|
Sheetsy::Converter.new(source, destination, options).run
|
32
32
|
end
|
33
33
|
|
34
|
+
desc "reader", "Read JSON sheets"
|
35
|
+
option :source, type: :string, aliases: :s
|
36
|
+
option :debug, type: :boolean, default: false
|
37
|
+
def reader
|
38
|
+
source = if options[:source]
|
39
|
+
options[:source]
|
40
|
+
elsif ENV.key?("SOURCE")
|
41
|
+
ENV.fetch("SOURCE")
|
42
|
+
else
|
43
|
+
get_input("Source Directory", Dir.pwd)
|
44
|
+
end
|
45
|
+
|
46
|
+
Sheetsy::Reader.new(source, options).run
|
47
|
+
end
|
48
|
+
|
34
49
|
private
|
35
50
|
|
36
51
|
def get_input(text, default)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sheetsy
|
4
|
+
class JSONFile
|
5
|
+
attr_reader :file_path, :data
|
6
|
+
|
7
|
+
def initialize(file_path)
|
8
|
+
@file_path = file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def data
|
12
|
+
@data ||= JSON.parse(File.read(file_path))
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#<#{self.class}:#{file_path}>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sheetsy
|
4
|
+
class Reader
|
5
|
+
attr_reader :source, :options, :data
|
6
|
+
|
7
|
+
def initialize(source, options = {})
|
8
|
+
@source = source
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
debug "Files found: #{files.count}"
|
14
|
+
|
15
|
+
progress_bar.progress = 0
|
16
|
+
|
17
|
+
@data = files.map do |file|
|
18
|
+
ret = JSONFile.new(file)
|
19
|
+
progress_bar.increment
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def overwrite?
|
25
|
+
@overwrite ||= options[:overwrite]
|
26
|
+
end
|
27
|
+
|
28
|
+
def debug?
|
29
|
+
@debug ||= options[:debug]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def files
|
35
|
+
@files ||= Dir.glob(File.join(source, "**/*.{json}"))
|
36
|
+
end
|
37
|
+
|
38
|
+
def progress_bar
|
39
|
+
@progress_bar ||= ProgressBar.create(title: "Files", total: files.count)
|
40
|
+
end
|
41
|
+
|
42
|
+
def debug(str)
|
43
|
+
return unless debug?
|
44
|
+
|
45
|
+
progress_bar.log str
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sheetsy/version.rb
CHANGED
data/lib/sheetsy.rb
CHANGED
@@ -3,11 +3,13 @@
|
|
3
3
|
require "json"
|
4
4
|
require "roo"
|
5
5
|
require "csv"
|
6
|
-
require "pry"
|
6
|
+
# require "pry"
|
7
7
|
require "ruby-progressbar"
|
8
8
|
|
9
9
|
require_relative "sheetsy/version"
|
10
10
|
require_relative "sheetsy/converter"
|
11
|
+
require_relative "sheetsy/json_file"
|
12
|
+
require_relative "sheetsy/reader"
|
11
13
|
require_relative "sheetsy/cli"
|
12
14
|
|
13
15
|
module Sheetsy
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheetsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
@@ -115,6 +115,8 @@ files:
|
|
115
115
|
- lib/sheetsy.rb
|
116
116
|
- lib/sheetsy/cli.rb
|
117
117
|
- lib/sheetsy/converter.rb
|
118
|
+
- lib/sheetsy/json_file.rb
|
119
|
+
- lib/sheetsy/reader.rb
|
118
120
|
- lib/sheetsy/version.rb
|
119
121
|
- sig/sheetsy.rbs
|
120
122
|
homepage: https://github.com/ryanwjackson/sheetsy
|