sepparator 0.0.4 → 0.0.5
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 +4 -4
- data/Gemfile.lock +11 -11
- data/lib/sepparator/spreadsheet_converter.rb +13 -10
- data/sepparator.gemspec +1 -1
- data/spec/sepparator/spreadsheet_converter_spec.rb +0 -7
- data/spec/sepparator_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba71e463fa74383b9f14a35f2d96691917b62bd
|
4
|
+
data.tar.gz: 343953fd6024f90650bbac58c74c28bd8144a283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2986dc70483b662947a661f0b3fb9fa58980296be1696256ad792442851988d690683068951ba2562eb754df6ca80eddeb9ab2c4694e20f9a4ae08fa5bee26df
|
7
|
+
data.tar.gz: f5de91cdee6aa37ddd8969e0b7146787c3ad4416b870d3b63e2e1078a7ba5af85e10d86da7c911ecf7186bf5c3e6feb3f54986606f016c4442a90a1ca2d6f4c3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sepparator (0.0.
|
4
|
+
sepparator (0.0.5)
|
5
5
|
simple_xlsx_writer
|
6
6
|
thor
|
7
7
|
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
fast_xs (0.8.0)
|
14
14
|
ffi (1.9.0)
|
15
15
|
formatador (0.2.4)
|
16
|
-
guard (1.8.
|
16
|
+
guard (1.8.2)
|
17
17
|
formatador (>= 0.2.4)
|
18
18
|
listen (>= 1.0.0)
|
19
19
|
lumberjack (>= 1.0.2)
|
@@ -27,7 +27,7 @@ GEM
|
|
27
27
|
rb-inotify (>= 0.9)
|
28
28
|
rb-kqueue (>= 0.2)
|
29
29
|
lumberjack (1.0.4)
|
30
|
-
method_source (0.8.
|
30
|
+
method_source (0.8.2)
|
31
31
|
pry (0.9.12.2)
|
32
32
|
coderay (~> 1.0.5)
|
33
33
|
method_source (~> 0.8)
|
@@ -38,19 +38,19 @@ GEM
|
|
38
38
|
ffi (>= 0.5.0)
|
39
39
|
rb-kqueue (0.2.0)
|
40
40
|
ffi (>= 0.5.0)
|
41
|
-
rspec (2.
|
42
|
-
rspec-core (~> 2.
|
43
|
-
rspec-expectations (~> 2.
|
44
|
-
rspec-mocks (~> 2.
|
45
|
-
rspec-core (2.
|
46
|
-
rspec-expectations (2.
|
41
|
+
rspec (2.14.1)
|
42
|
+
rspec-core (~> 2.14.0)
|
43
|
+
rspec-expectations (~> 2.14.0)
|
44
|
+
rspec-mocks (~> 2.14.0)
|
45
|
+
rspec-core (2.14.4)
|
46
|
+
rspec-expectations (2.14.0)
|
47
47
|
diff-lcs (>= 1.1.3, < 2.0)
|
48
|
-
rspec-mocks (2.
|
48
|
+
rspec-mocks (2.14.2)
|
49
49
|
rubyzip (0.9.9)
|
50
50
|
simple_xlsx_writer (0.5.3)
|
51
51
|
fast_xs (>= 0.7.3)
|
52
52
|
rubyzip (>= 0.9.4)
|
53
|
-
slop (3.4.
|
53
|
+
slop (3.4.6)
|
54
54
|
thor (0.18.1)
|
55
55
|
|
56
56
|
PLATFORMS
|
@@ -12,24 +12,27 @@ module Sepparator
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def convert(csv_path, xls_path, sheet_name: 'from CSV')
|
15
|
-
raise ArgumentError, "destination file exists: #{xls_path}" if File.exists?(xls_path)
|
16
15
|
raise ArgumentError, "file not found: #{csv_path}" unless File.exists?(csv_path)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
sheet.add_row(csv_row)
|
21
|
-
end
|
16
|
+
create_xlsx(xls_path, sheet_name) do |sheet|
|
17
|
+
CSV.foreach(csv_path, col_sep: col_sep, converters: [:numeric, :date_time, :date]) do |csv_row|
|
18
|
+
sheet.add_row(csv_row)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
def convert_from_string(csv_string, xls_path, sheet_name: 'from CSV')
|
27
|
-
|
24
|
+
create_xlsx(xls_path, sheet_name) do |sheet|
|
25
|
+
CSV.parse(csv_string, col_sep: col_sep, converters: [:numeric, :date_time, :date]) do |csv_row|
|
26
|
+
sheet.add_row(csv_row)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def create_xlsx(xls_path, sheet_name)
|
28
33
|
SimpleXlsx::Serializer.new(xls_path) do |doc|
|
29
34
|
doc.add_sheet(sheet_name || 'from CSV') do |sheet|
|
30
|
-
|
31
|
-
sheet.add_row(csv_row)
|
32
|
-
end
|
35
|
+
yield sheet
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/sepparator.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "sepparator"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.5'
|
8
8
|
spec.authors = ["Andreas Brandl"]
|
9
9
|
spec.email = ["github@andreas-brandl.de"]
|
10
10
|
spec.description = %q{tool for working with CSV files, it supports conversion to Excel files and import to databases.}
|
@@ -22,12 +22,8 @@ describe Sepparator::SpreadsheetConverter do
|
|
22
22
|
subject
|
23
23
|
expect(File.exists?(xls_path)).to be_true
|
24
24
|
end
|
25
|
-
it 'raises when the destination file already exists' do
|
26
|
-
expect{described_class.new.convert('/some/non/existing/file.csv', Tempfile.new('blafoo').path)}.to raise_error(ArgumentError, /destination file exists/)
|
27
|
-
end
|
28
25
|
end
|
29
26
|
context '#convert' do
|
30
|
-
#let(:xls_path) { Tempfile.new('convert-to-xlsx')}
|
31
27
|
let(:xls_path) { '/tmp/example.xlsx' }
|
32
28
|
let(:csv_path) { File.join(__dir__, 'example.csv')}
|
33
29
|
subject { described_class.new.convert(csv_path, xls_path)}
|
@@ -46,9 +42,6 @@ describe Sepparator::SpreadsheetConverter do
|
|
46
42
|
expect{described_class.new.convert('/some/non/existing/file.csv', xls_path)}.to raise_error(ArgumentError, /file not found/)
|
47
43
|
end
|
48
44
|
|
49
|
-
it 'raises when the destination file already exists' do
|
50
|
-
expect{described_class.new.convert('/some/non/existing/file.csv', Tempfile.new('blafoo').path)}.to raise_error(ArgumentError, /destination file exists/)
|
51
|
-
end
|
52
45
|
end
|
53
46
|
|
54
47
|
end
|
data/spec/sepparator_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Sepparator do
|
|
8
8
|
csv_path = 'foo/bar.csv'
|
9
9
|
xls_path = 'bla/fu.xls'
|
10
10
|
sheet_name = 'my sheet'
|
11
|
-
converter =
|
11
|
+
converter = double
|
12
12
|
Sepparator::SpreadsheetConverter.should_receive(:new).with(col_sep: col_sep).and_return(converter)
|
13
13
|
converter.should_receive(:convert).with(csv_path, xls_path, sheet_name: sheet_name)
|
14
14
|
|