sheetsy 1.1.0 → 1.2.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/reader.rb +60 -0
- data/lib/sheetsy/version.rb +1 -1
- data/lib/sheetsy.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46b076008cee61a9a62811da5a448d4d67584867944789863fad1c8ed9463e7c
|
4
|
+
data.tar.gz: 3d61813f2caa7d34308f6cdced0458ff88964fdda77496197747f37c1eecaf4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bed1161ce8242f20335fc8ad03bff03629936bd2f965bc25570d351b542f6b178abb4df7c186c67b70a0543d451cf1398fab32db635b3ebad6873de698911bd
|
7
|
+
data.tar.gz: f71ddaf63e56078256009e72fdadd539c53069d9bbb5e615907e2b2c152059c0f9b442d7dac3c1d9d2820990101bce2307b5e0476ee42d257f59609fafbe29e2
|
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,60 @@
|
|
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
|
+
ret = {}
|
17
|
+
|
18
|
+
files.each do |file|
|
19
|
+
ret[file] = process_file(file)
|
20
|
+
progress_bar.increment
|
21
|
+
end
|
22
|
+
|
23
|
+
@data = ret
|
24
|
+
end
|
25
|
+
|
26
|
+
def overwrite?
|
27
|
+
@overwrite ||= options[:overwrite]
|
28
|
+
end
|
29
|
+
|
30
|
+
def debug?
|
31
|
+
@debug ||= options[:debug]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def files
|
37
|
+
@files ||= Dir.glob(File.join(source, "**/*.{json}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def progress_bar
|
41
|
+
@progress_bar ||= ProgressBar.create(title: "Files", total: files.count)
|
42
|
+
end
|
43
|
+
|
44
|
+
def debug(str)
|
45
|
+
return unless debug?
|
46
|
+
|
47
|
+
progress_bar.log str
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_file(file)
|
51
|
+
debug "File: #{file}"
|
52
|
+
|
53
|
+
JSON.parse(File.read(file))
|
54
|
+
end
|
55
|
+
|
56
|
+
def progress_bar
|
57
|
+
@progress_bar ||= ProgressBar.create(title: "Files", total: files.count)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/sheetsy/version.rb
CHANGED
data/lib/sheetsy.rb
CHANGED
@@ -3,11 +3,12 @@
|
|
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/reader"
|
11
12
|
require_relative "sheetsy/cli"
|
12
13
|
|
13
14
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/sheetsy.rb
|
116
116
|
- lib/sheetsy/cli.rb
|
117
117
|
- lib/sheetsy/converter.rb
|
118
|
+
- lib/sheetsy/reader.rb
|
118
119
|
- lib/sheetsy/version.rb
|
119
120
|
- sig/sheetsy.rbs
|
120
121
|
homepage: https://github.com/ryanwjackson/sheetsy
|