sepparator 0.0.3 → 0.0.4
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 +1 -1
- data/lib/sepparator/spreadsheet_converter.rb +11 -0
- data/sepparator.gemspec +1 -1
- data/spec/sepparator/spreadsheet_converter_spec.rb +16 -0
- metadata +2 -4
- data/spec/sepparator/spreadsheet_converter.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0db8dffa7a89eb9c7f4e572a49921059edd0342
|
4
|
+
data.tar.gz: ed95d128b87536a256141928a69be1948175f6c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e56370c5f62fbc0ac04e86737c1792a45ead185380e764516e59cc03ea78dadea05dfedfa202864cc9340c05d00c09030bbb31967ae5aa3e5d8d49d65bf36d
|
7
|
+
data.tar.gz: f5cb224bb669339926a216f75221d2b6e95e37eb4cca80f4433c56ac01d05aac842f469c968dc877baa98589ceca2be28d4eed4b3358e81d837431580fecdeea
|
data/Gemfile.lock
CHANGED
@@ -23,6 +23,17 @@ module Sepparator
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def convert_from_string(csv_string, xls_path, sheet_name: 'from CSV')
|
27
|
+
raise ArgumentError, "destination file exists: #{xls_path}" if File.exists?(xls_path)
|
28
|
+
SimpleXlsx::Serializer.new(xls_path) do |doc|
|
29
|
+
doc.add_sheet(sheet_name || 'from CSV') do |sheet|
|
30
|
+
CSV.parse(csv_string, col_sep: col_sep, converters: [:numeric, :date_time, :date]) do |csv_row|
|
31
|
+
sheet.add_row(csv_row)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
26
37
|
end
|
27
38
|
|
28
39
|
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.4'
|
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.}
|
@@ -10,6 +10,22 @@ describe Sepparator::SpreadsheetConverter do
|
|
10
10
|
expect(described_class.new(col_sep: sep).col_sep).to eq(sep)
|
11
11
|
end
|
12
12
|
|
13
|
+
context '#convert_from_string' do
|
14
|
+
let(:csv_string) { File.open(File.join(__dir__, 'example.csv')).read }
|
15
|
+
let(:xls_path) { Tempfile.new('convert-to-xlsx').path }
|
16
|
+
subject { described_class.new.convert_from_string(csv_string, xls_path) }
|
17
|
+
|
18
|
+
before { FileUtils.rm_f xls_path }
|
19
|
+
|
20
|
+
it "converts a csv string" do
|
21
|
+
# don't comparing xlsx files here
|
22
|
+
subject
|
23
|
+
expect(File.exists?(xls_path)).to be_true
|
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
|
+
end
|
13
29
|
context '#convert' do
|
14
30
|
#let(:xls_path) { Tempfile.new('convert-to-xlsx')}
|
15
31
|
let(:xls_path) { '/tmp/example.xlsx' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sepparator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Brandl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_xlsx_writer
|
@@ -146,7 +146,6 @@ files:
|
|
146
146
|
- lib/sepparator/spreadsheet_converter.rb
|
147
147
|
- sepparator.gemspec
|
148
148
|
- spec/sepparator/example.csv
|
149
|
-
- spec/sepparator/spreadsheet_converter.rb
|
150
149
|
- spec/sepparator/spreadsheet_converter_spec.rb
|
151
150
|
- spec/sepparator_spec.rb
|
152
151
|
- spec/spec_helper.rb
|
@@ -177,7 +176,6 @@ summary: tool for working with CSV files, it supports conversion to Excel files
|
|
177
176
|
import to databases.
|
178
177
|
test_files:
|
179
178
|
- spec/sepparator/example.csv
|
180
|
-
- spec/sepparator/spreadsheet_converter.rb
|
181
179
|
- spec/sepparator/spreadsheet_converter_spec.rb
|
182
180
|
- spec/sepparator_spec.rb
|
183
181
|
- spec/spec_helper.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sepparator/spreadsheet_converter'
|
3
|
-
require 'tempfile'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
module Sepparator
|
7
|
-
describe SpreadsheetConverter do
|
8
|
-
|
9
|
-
it 'remembers the column separator' do
|
10
|
-
sep = 'foobar'
|
11
|
-
expect(described_class.new(col_sep: sep).col_sep).to eq(sep)
|
12
|
-
end
|
13
|
-
|
14
|
-
context '#convert' do
|
15
|
-
let(:xls_path) { Tempfile.new('convert-to-xlsx').path }
|
16
|
-
let(:csv_path) { File.join(__dir__, 'example.csv')}
|
17
|
-
subject { described_class.new.convert(csv_path, xls_path)}
|
18
|
-
|
19
|
-
before do
|
20
|
-
FileUtils.rm_f xls_path
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'converts a CSV file' do
|
24
|
-
# don't comparing xlsx files here
|
25
|
-
subject
|
26
|
-
expect(File.exists?(xls_path)).to be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'raises when the source file was not found' do
|
30
|
-
expect{described_class.new.convert('/some/non/existing/file.csv', xls_path)}.to raise_error(ArgumentError, /file not found/)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'raises when the destination file already exists' do
|
34
|
-
expect{described_class.new.convert('/some/non/existing/file.csv', Tempfile.new('blafoo').path)}.to raise_error(ArgumentError, /destination file exists/)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|