csv-xlsx-converter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +19 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/csv-xlsx-converter.gemspec +72 -0
- data/data/sample-1.csv +3 -0
- data/lib/csv_xlsx_converter.rb +11 -0
- data/lib/csv_xlsx_converter/cli.rb +55 -0
- data/lib/csv_xlsx_converter/converter.rb +55 -0
- data/lib/csv_xlsx_converter/filename.rb +23 -0
- data/spec/lib/csv_xlsx_converter/cli_spec.rb +46 -0
- data/spec/lib/csv_xlsx_converter/converter_spec.rb +40 -0
- data/spec/lib/csv_xlsx_converter/filename_spec.rb +38 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 430ad95ad827b21832da6d3ba4ba0839087d47b5
|
4
|
+
data.tar.gz: 2223329ccc05725f8df12de6fa051b7927c0ad40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11a9e1cac0da7d17872f2bc7f1ddcd7746d96b121b17115e15e69008f7c407d2b7925f0611c66466c331c7a683f3f5b2c60d9fb8bf37025e585a3fdaad8b96e5
|
7
|
+
data.tar.gz: 4f792c337ff99f0962aef37b0a4d13350619aa7e457437f5760fdcee3c42c0fb52f6f0ef1dfbf4cfa54fecbbca314128bfe1d5a2c3335a9c19d034bb574aa7d0
|
data/.document
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
builder (3.1.4)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
diff-lcs (1.2.5)
|
9
|
+
faraday (0.9.0)
|
10
|
+
multipart-post (>= 1.2, < 3)
|
11
|
+
git (1.2.7)
|
12
|
+
github_api (0.12.2)
|
13
|
+
addressable (~> 2.3)
|
14
|
+
descendants_tracker (~> 0.0.4)
|
15
|
+
faraday (~> 0.8, < 0.10)
|
16
|
+
hashie (>= 3.3)
|
17
|
+
multi_json (>= 1.7.5, < 2.0)
|
18
|
+
nokogiri (~> 1.6.3)
|
19
|
+
oauth2
|
20
|
+
hashie (3.3.2)
|
21
|
+
highline (1.6.21)
|
22
|
+
jeweler (2.0.1)
|
23
|
+
builder
|
24
|
+
bundler (>= 1.0)
|
25
|
+
git (>= 1.2.5)
|
26
|
+
github_api
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.5.10)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
json (1.8.1)
|
32
|
+
jwt (1.2.0)
|
33
|
+
mini_portile (0.6.2)
|
34
|
+
multi_json (1.10.1)
|
35
|
+
multi_xml (0.5.5)
|
36
|
+
multipart-post (2.0.0)
|
37
|
+
nokogiri (1.6.5)
|
38
|
+
mini_portile (~> 0.6.0)
|
39
|
+
oauth2 (1.0.0)
|
40
|
+
faraday (>= 0.8, < 0.10)
|
41
|
+
jwt (~> 1.0)
|
42
|
+
multi_json (~> 1.3)
|
43
|
+
multi_xml (~> 0.5)
|
44
|
+
rack (~> 1.2)
|
45
|
+
rack (1.5.2)
|
46
|
+
rake (0.9.6)
|
47
|
+
rdoc (3.12.2)
|
48
|
+
json (~> 1.4)
|
49
|
+
rspec (2.99.0)
|
50
|
+
rspec-core (~> 2.99.0)
|
51
|
+
rspec-expectations (~> 2.99.0)
|
52
|
+
rspec-mocks (~> 2.99.0)
|
53
|
+
rspec-core (2.99.2)
|
54
|
+
rspec-expectations (2.99.2)
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
+
rspec-mocks (2.99.2)
|
57
|
+
rubyXL (3.3.2)
|
58
|
+
nokogiri (>= 1.4.4)
|
59
|
+
rubyzip (>= 1.1.6)
|
60
|
+
rubyzip (1.1.6)
|
61
|
+
thread_safe (0.3.4)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
bundler (~> 1.0)
|
68
|
+
jeweler (~> 2.0.1)
|
69
|
+
rake
|
70
|
+
rdoc (~> 3.12)
|
71
|
+
rspec (~> 2.13)
|
72
|
+
rubyXL (>= 3.3.2)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 if1live
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= csv-xlsx-converter
|
2
|
+
{<img src="https://travis-ci.org/if1live/csv-xlsx-converter.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/if1live/csv-xlsx-converter]
|
3
|
+
|
4
|
+
== To Install:
|
5
|
+
gem install rubyXL
|
6
|
+
# or...
|
7
|
+
bundle install
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
Command line script get one or two arguments.
|
11
|
+
|
12
|
+
1. First argument : Input filename (Required)
|
13
|
+
2. Second argument : Output filename (Optional)
|
14
|
+
|
15
|
+
If second argment is not predefined, use first filename as excel xlsx filename.
|
16
|
+
For example, input filename is foo.csv then output filename is foo.xlsx.
|
17
|
+
|
18
|
+
=== CSV to Excel xlsx:
|
19
|
+
csv_xlsx_converter.rb input.csv
|
20
|
+
csv_xlsx_converter.rb input.csv output.xlsx
|
21
|
+
|
22
|
+
=== Excel xlsx to CSV:
|
23
|
+
csv_xlsx_converter.rb input.xlsx
|
24
|
+
csv_xlsx_converter.rb input.xlsx output.csv
|
25
|
+
|
26
|
+
== Copyright
|
27
|
+
|
28
|
+
Copyright (c) 2015 if1live. See LICENSE.txt for
|
29
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "csv-xlsx-converter"
|
18
|
+
gem.homepage = "http://github.com/if1live/csv-xlsx-converter"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Convert CSV to Excel xlsx, Excel xlsx to CSV.}
|
21
|
+
gem.description = %Q{Convert CSV to Excel xlsx, Excel xlsx to CSV.}
|
22
|
+
gem.email = "libsora25@gmail.com"
|
23
|
+
gem.authors = ["if1live"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec)
|
30
|
+
task :test => :spec
|
31
|
+
|
32
|
+
desc "Code coverage detail"
|
33
|
+
task :simplecov do
|
34
|
+
ENV['COVERAGE'] = "true"
|
35
|
+
Rake::Task['test'].execute
|
36
|
+
end
|
37
|
+
|
38
|
+
task :default => :test
|
39
|
+
|
40
|
+
require 'rdoc/task'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "csv-xlsx-converter #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: csv-xlsx-converter 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "csv-xlsx-converter"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["if1live"]
|
14
|
+
s.date = "2015-01-13"
|
15
|
+
s.description = "Convert CSV to Excel xlsx, Excel xlsx to CSV."
|
16
|
+
s.email = "libsora25@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".travis.yml",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"csv-xlsx-converter.gemspec",
|
31
|
+
"data/sample-1.csv",
|
32
|
+
"lib/csv_xlsx_converter.rb",
|
33
|
+
"lib/csv_xlsx_converter/cli.rb",
|
34
|
+
"lib/csv_xlsx_converter/converter.rb",
|
35
|
+
"lib/csv_xlsx_converter/filename.rb",
|
36
|
+
"spec/lib/csv_xlsx_converter/cli_spec.rb",
|
37
|
+
"spec/lib/csv_xlsx_converter/converter_spec.rb",
|
38
|
+
"spec/lib/csv_xlsx_converter/filename_spec.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/if1live/csv-xlsx-converter"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.rubygems_version = "2.2.2"
|
43
|
+
s.summary = "Convert CSV to Excel xlsx, Excel xlsx to CSV."
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 4
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<rubyXL>, [">= 3.3.2"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
51
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
53
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.13"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rubyXL>, [">= 3.3.2"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
58
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.13"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rubyXL>, [">= 3.3.2"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
66
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.13"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/data/sample-1.csv
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative "filename"
|
4
|
+
|
5
|
+
module CsvXlsxConverter
|
6
|
+
def self.handle_in param
|
7
|
+
input = param[0]
|
8
|
+
|
9
|
+
if self.csv_filename? input
|
10
|
+
conv = self::CsvToXlsx.new input
|
11
|
+
output = self.to_xlsx_filename input
|
12
|
+
conv.convert output
|
13
|
+
|
14
|
+
elsif self.xlsx_filename? input
|
15
|
+
conv = self::XlsxToCsv.new input
|
16
|
+
output = self.to_csv_filename input
|
17
|
+
conv.convert output
|
18
|
+
|
19
|
+
else
|
20
|
+
puts "not vaild argv"
|
21
|
+
puts "input: #{input}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.handle_inout param
|
26
|
+
input = param[0]
|
27
|
+
output = param[1]
|
28
|
+
|
29
|
+
begin
|
30
|
+
if self.csv_filename? input
|
31
|
+
conv = self::CsvToXlsx.new input
|
32
|
+
conv.convert output
|
33
|
+
|
34
|
+
elsif self.xlsx_filename? input
|
35
|
+
conv = self::XlsxToCsv.new input
|
36
|
+
conv.convert output
|
37
|
+
end
|
38
|
+
rescue
|
39
|
+
puts "not vaild argv"
|
40
|
+
puts "input: #{input}"
|
41
|
+
puts "output: #{output}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.main
|
46
|
+
if ARGV.size == 1
|
47
|
+
handle_in ARGV
|
48
|
+
elsif ARGV.size == 2
|
49
|
+
handle_inout ARGV
|
50
|
+
else
|
51
|
+
puts "Usage: #{$0} <input:*.csv/*.xlsx>"
|
52
|
+
puts "Usage: #{$0} <input:*.csv/*.xlsx> <output:*.cvs/*.xlsx>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
require "rubyXL"
|
5
|
+
|
6
|
+
module CsvXlsxConverter
|
7
|
+
class CsvToXlsx
|
8
|
+
def initialize(input_file)
|
9
|
+
raise ArgumentError, "input file is not csv" unless CsvXlsxConverter::csv_filename? input_file
|
10
|
+
@input_file = input_file
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert(output_file)
|
14
|
+
raise ArgumentError, "output file is not xlsx" unless CsvXlsxConverter::xlsx_filename? output_file
|
15
|
+
|
16
|
+
workbook = RubyXL::Workbook.new
|
17
|
+
worksheet = workbook[0]
|
18
|
+
|
19
|
+
CSV.foreach(@input_file) do |row|
|
20
|
+
# http://stackoverflow.com/questions/12407035/ruby-csv-get-current-line-row-number
|
21
|
+
row_idx = $. - 1
|
22
|
+
row.each_with_index do |item, index|
|
23
|
+
worksheet.add_cell row_idx, index, item
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
workbook.write output_file
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class XlsxToCsv
|
32
|
+
def initialize(input_file)
|
33
|
+
raise ArgumentError, "input file is not xlsx" unless CsvXlsxConverter::xlsx_filename? input_file
|
34
|
+
@input_file = input_file
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert(output_file)
|
38
|
+
raise ArgumentError, "output file is not csv" unless CsvXlsxConverter::csv_filename? output_file
|
39
|
+
|
40
|
+
CSV.open(output_file, "wb") do |csv|
|
41
|
+
workbook = RubyXL::Parser.parse @input_file
|
42
|
+
worksheet = workbook[0]
|
43
|
+
|
44
|
+
worksheet.each_with_index do |row, row_idx|
|
45
|
+
row_data = []
|
46
|
+
(0...row.size).each do |col_idx|
|
47
|
+
cell = row[col_idx]
|
48
|
+
row_data << cell.value
|
49
|
+
end
|
50
|
+
csv << row_data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
|
4
|
+
module CsvXlsxConverter
|
5
|
+
RE_CSV_EXTENSION = Regexp.new("\.csv$", Regexp::IGNORECASE)
|
6
|
+
RE_XLSX_EXTENSION = Regexp.new("\.xlsx$", Regexp::IGNORECASE)
|
7
|
+
|
8
|
+
def self.csv_filename? filename
|
9
|
+
filename =~ RE_CSV_EXTENSION ? true : false
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.xlsx_filename? filename
|
13
|
+
filename =~ RE_XLSX_EXTENSION ? true : false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.to_xlsx_filename csv_filename
|
17
|
+
csv_filename.gsub RE_CSV_EXTENSION, ".xlsx"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.to_csv_filename xlsx_filename
|
21
|
+
xlsx_filename.gsub RE_XLSX_EXTENSION, ".csv"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require "csv_xlsx_converter/cli"
|
5
|
+
require "csv_xlsx_converter/converter"
|
6
|
+
|
7
|
+
|
8
|
+
def get_data_file filename
|
9
|
+
root_path = __FILE__
|
10
|
+
4.times { root_path = File.dirname(root_path) }
|
11
|
+
File.join(root_path, 'data', filename)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe CsvXlsxConverter do
|
16
|
+
describe ".main" do
|
17
|
+
before(:each) do
|
18
|
+
temp = Tempfile.new(["temp", ".xlsx"])
|
19
|
+
@temp_file = temp.path
|
20
|
+
temp.unlink
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
output = Tempfile.new(["output", ".csv"])
|
25
|
+
@output_file = output.path
|
26
|
+
output.unlink
|
27
|
+
end
|
28
|
+
|
29
|
+
it "csv -> xlsx -> csv" do
|
30
|
+
input_file = get_data_file "sample-1.csv"
|
31
|
+
|
32
|
+
csv_xlsx = CsvXlsxConverter::CsvToXlsx.new input_file
|
33
|
+
csv_xlsx.convert @temp_file
|
34
|
+
|
35
|
+
xlsx_csv = CsvXlsxConverter::XlsxToCsv.new @temp_file
|
36
|
+
xlsx_csv.convert @output_file
|
37
|
+
|
38
|
+
expect(true).to eq(FileUtils.compare_file input_file, @output_file)
|
39
|
+
end
|
40
|
+
|
41
|
+
after(:each) do
|
42
|
+
File.delete(@temp_file)
|
43
|
+
File.delete(@output_file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "csv_xlsx_converter/converter"
|
4
|
+
|
5
|
+
describe CsvXlsxConverter::CsvToXlsx do
|
6
|
+
describe "#initialize" do
|
7
|
+
it "csv file -> success" do
|
8
|
+
CsvXlsxConverter::CsvToXlsx.new "foo.csv"
|
9
|
+
end
|
10
|
+
it "not csv file -> exception" do
|
11
|
+
expect { CsvXlsxConverter::CsvToXlsx.new "foo.xlsx" }.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#convert" do
|
16
|
+
let(:converter) { CsvXlsxConverter::CsvToXlsx.new "foo.csv" }
|
17
|
+
it "output is not xlsx -> exception" do
|
18
|
+
expect { converter.convert "foo.txt" }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe CsvXlsxConverter::XlsxToCsv do
|
25
|
+
describe "#initialize" do
|
26
|
+
it "xlsx file -> success" do
|
27
|
+
CsvXlsxConverter::XlsxToCsv.new "foo.xlsx"
|
28
|
+
end
|
29
|
+
it "not xlsx file -> exception" do
|
30
|
+
expect {CsvXlsxConverter::XlsxToCsv.new "foo.csv" }.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#convert" do
|
35
|
+
let(:converter) { CsvXlsxConverter::XlsxToCsv.new "foo.xlsx" }
|
36
|
+
it "output is not csv -> exception" do
|
37
|
+
expect { converter.convert "foo.txt" }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "csv_xlsx_converter/filename"
|
3
|
+
|
4
|
+
describe CsvXlsxConverter do
|
5
|
+
describe ".csv_filename?" do
|
6
|
+
it "csv file" do
|
7
|
+
expect(true).to eq(CsvXlsxConverter::csv_filename? "foo.csv")
|
8
|
+
expect(true).to eq(CsvXlsxConverter::csv_filename? "foo.CSV")
|
9
|
+
end
|
10
|
+
it "not csv file" do
|
11
|
+
expect(false).to eq(CsvXlsxConverter::csv_filename? "foo.xlsx")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".xlsx_filename?" do
|
16
|
+
it "xlsx file" do
|
17
|
+
expect(true).to eq(CsvXlsxConverter::xlsx_filename? "foo.xlsx")
|
18
|
+
expect(true).to eq(CsvXlsxConverter::xlsx_filename? "foo.XLSX")
|
19
|
+
end
|
20
|
+
it "not xlsx file" do
|
21
|
+
expect(false).to eq(CsvXlsxConverter::xlsx_filename? "foo.csv")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".to_xlsx_filename" do
|
26
|
+
it "csv to xlsx" do
|
27
|
+
expect("foo.xlsx").to eq(CsvXlsxConverter::to_xlsx_filename "foo.csv")
|
28
|
+
expect("foo.xlsx").to eq(CsvXlsxConverter::to_xlsx_filename "foo.CSV")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".to_csv_filename" do
|
33
|
+
it "xlsx to csv" do
|
34
|
+
expect("foo.csv").to eq(CsvXlsxConverter::to_csv_filename "foo.xlsx")
|
35
|
+
expect("foo.csv").to eq(CsvXlsxConverter::to_csv_filename "foo.XLSX")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csv-xlsx-converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- if1live
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyXL
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.3.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rdoc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.12'
|
97
|
+
description: Convert CSV to Excel xlsx, Excel xlsx to CSV.
|
98
|
+
email: libsora25@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- ".document"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- csv-xlsx-converter.gemspec
|
114
|
+
- data/sample-1.csv
|
115
|
+
- lib/csv_xlsx_converter.rb
|
116
|
+
- lib/csv_xlsx_converter/cli.rb
|
117
|
+
- lib/csv_xlsx_converter/converter.rb
|
118
|
+
- lib/csv_xlsx_converter/filename.rb
|
119
|
+
- spec/lib/csv_xlsx_converter/cli_spec.rb
|
120
|
+
- spec/lib/csv_xlsx_converter/converter_spec.rb
|
121
|
+
- spec/lib/csv_xlsx_converter/filename_spec.rb
|
122
|
+
homepage: http://github.com/if1live/csv-xlsx-converter
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Convert CSV to Excel xlsx, Excel xlsx to CSV.
|
146
|
+
test_files: []
|