sheetsy 1.2.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b076008cee61a9a62811da5a448d4d67584867944789863fad1c8ed9463e7c
4
- data.tar.gz: 3d61813f2caa7d34308f6cdced0458ff88964fdda77496197747f37c1eecaf4d
3
+ metadata.gz: 961ad80de96cffaf49ca35df5f2d041c28304f7ada1ca1c8ea615d7165358d33
4
+ data.tar.gz: 31e77af45fafb194cd03d397360f0cb822778fe42dc1a8cdef60fda9f3bf5ae3
5
5
  SHA512:
6
- metadata.gz: 9bed1161ce8242f20335fc8ad03bff03629936bd2f965bc25570d351b542f6b178abb4df7c186c67b70a0543d451cf1398fab32db635b3ebad6873de698911bd
7
- data.tar.gz: f71ddaf63e56078256009e72fdadd539c53069d9bbb5e615907e2b2c152059c0f9b442d7dac3c1d9d2820990101bce2307b5e0476ee42d257f59609fafbe29e2
6
+ metadata.gz: 632ecfa2ce5b8acd1a279f31087ec037a2d0db2d62c1cc07c9f89e39cc1bd36df75c3f1050b8e3c75edd84ed39a923a5ca464bc077bf3451ec2793b46caabe52
7
+ data.tar.gz: ed6813861f014ca1c00c7a5ef04d89c6ccb60f818990fe0a3a75ee60d99493841ad95993adc864945aacb8f55fccb4f5a2fede47431c4d7846e2b89a1b9f50bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sheetsy (1.2.0)
4
+ sheetsy (1.3.1)
5
5
  rake (~> 13.0)
6
6
  roo
7
7
  rspec (~> 3.0)
@@ -50,8 +50,8 @@ GEM
50
50
  rspec-mocks (3.13.0)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.13.0)
53
- rspec-support (3.13.0)
54
- rubocop (1.60.2)
53
+ rspec-support (3.13.1)
54
+ rubocop (1.61.0)
55
55
  json (~> 2.3)
56
56
  language_server-protocol (>= 3.17.0)
57
57
  parallel (~> 1.10)
@@ -62,11 +62,11 @@ GEM
62
62
  rubocop-ast (>= 1.30.0, < 2.0)
63
63
  ruby-progressbar (~> 1.7)
64
64
  unicode-display_width (>= 2.4.0, < 3.0)
65
- rubocop-ast (1.30.0)
66
- parser (>= 3.2.1.0)
65
+ rubocop-ast (1.31.1)
66
+ parser (>= 3.3.0.4)
67
67
  ruby-progressbar (1.13.0)
68
68
  rubyzip (2.3.2)
69
- thor (1.3.0)
69
+ thor (1.3.1)
70
70
  unicode-display_width (2.5.0)
71
71
 
72
72
  PLATFORMS
@@ -49,7 +49,7 @@ module Sheetsy
49
49
  progress_bar.log str
50
50
  end
51
51
 
52
- def process_csv(file)
52
+ def process_csv(file) # rubocop:disable Metrics/MethodLength
53
53
  debug "Processing as CSV"
54
54
 
55
55
  output_file_path = File.join(destination, "#{nameify(file)}.json")
@@ -57,12 +57,16 @@ module Sheetsy
57
57
 
58
58
  debug "File #{output_file_path}"
59
59
 
60
- data = CSV.read(file, headers: true).map(&:to_h)
60
+ data = begin
61
+ CSV.read(file, headers: true).map(&:to_h)
62
+ rescue CSV::MalformedCSVError
63
+ CSV.read(file, headers: true, encoding: "iso-8859-1:utf-8").map(&:to_h)
64
+ end
61
65
  write_json(output_file_path, data)
62
66
  debug "Converted #{file} to #{output_file_path}\n\n"
63
67
  end
64
68
 
65
- def process_excel(file)
69
+ def process_excel(file) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
66
70
  debug "Processing as Excel"
67
71
  excel = Roo::Spreadsheet.open(file)
68
72
 
@@ -99,7 +103,7 @@ module Sheetsy
99
103
  process_excel(file)
100
104
  else
101
105
  debug "Unsupported file format: #{file}"
102
- return
106
+ nil
103
107
  end
104
108
  end
105
109
 
@@ -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
@@ -13,14 +13,12 @@ module Sheetsy
13
13
  debug "Files found: #{files.count}"
14
14
 
15
15
  progress_bar.progress = 0
16
- ret = {}
17
16
 
18
- files.each do |file|
19
- ret[file] = process_file(file)
17
+ @data = files.map do |file|
18
+ ret = JSONFile.new(file)
20
19
  progress_bar.increment
20
+ ret
21
21
  end
22
-
23
- @data = ret
24
22
  end
25
23
 
26
24
  def overwrite?
@@ -46,15 +44,5 @@ module Sheetsy
46
44
 
47
45
  progress_bar.log str
48
46
  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
47
  end
60
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sheetsy
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.1"
5
5
  end
data/lib/sheetsy.rb CHANGED
@@ -8,6 +8,7 @@ require "ruby-progressbar"
8
8
 
9
9
  require_relative "sheetsy/version"
10
10
  require_relative "sheetsy/converter"
11
+ require_relative "sheetsy/json_file"
11
12
  require_relative "sheetsy/reader"
12
13
  require_relative "sheetsy/cli"
13
14
 
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: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -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/json_file.rb
118
119
  - lib/sheetsy/reader.rb
119
120
  - lib/sheetsy/version.rb
120
121
  - sig/sheetsy.rbs