Module: CsvXlsxConverter
- Defined in:
- lib/csv_xlsx_converter/cli.rb,
lib/csv_xlsx_converter/filename.rb,
lib/csv_xlsx_converter/converter.rb
Defined Under Namespace
Classes: CsvToXlsx, XlsxToCsv
Constant Summary
collapse
- RE_CSV_EXTENSION =
Regexp.new("\.csv$", Regexp::IGNORECASE)
- RE_XLSX_EXTENSION =
Regexp.new("\.xlsx$", Regexp::IGNORECASE)
Class Method Summary
collapse
Class Method Details
.csv_filename?(filename) ⇒ Boolean
8
9
10
|
# File 'lib/csv_xlsx_converter/filename.rb', line 8
def self.csv_filename? filename
filename =~ RE_CSV_EXTENSION ? true : false
end
|
.handle_in(param) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/csv_xlsx_converter/cli.rb', line 6
def self.handle_in param
input = param[0]
if self.csv_filename? input
conv = self::CsvToXlsx.new input
output = self.to_xlsx_filename input
conv.convert output
elsif self.xlsx_filename? input
conv = self::XlsxToCsv.new input
output = self.to_csv_filename input
conv.convert output
else
puts "not vaild argv"
puts "input: #{input}"
end
end
|
.handle_inout(param) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/csv_xlsx_converter/cli.rb', line 25
def self.handle_inout param
input = param[0]
output = param[1]
begin
if self.csv_filename? input
conv = self::CsvToXlsx.new input
conv.convert output
elsif self.xlsx_filename? input
conv = self::XlsxToCsv.new input
conv.convert output
end
rescue
puts "not vaild argv"
puts "input: #{input}"
puts "output: #{output}"
end
end
|
.main ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/csv_xlsx_converter/cli.rb', line 45
def self.main
if ARGV.size == 1
handle_in ARGV
elsif ARGV.size == 2
handle_inout ARGV
else
puts "Usage: #{$0} <input:*.csv/*.xlsx>"
puts "Usage: #{$0} <input:*.csv/*.xlsx> <output:*.cvs/*.xlsx>"
end
end
|
.to_csv_filename(xlsx_filename) ⇒ Object
20
21
22
|
# File 'lib/csv_xlsx_converter/filename.rb', line 20
def self.to_csv_filename xlsx_filename
xlsx_filename.gsub RE_XLSX_EXTENSION, ".csv"
end
|
.to_xlsx_filename(csv_filename) ⇒ Object
16
17
18
|
# File 'lib/csv_xlsx_converter/filename.rb', line 16
def self.to_xlsx_filename csv_filename
csv_filename.gsub RE_CSV_EXTENSION, ".xlsx"
end
|
.xlsx_filename?(filename) ⇒ Boolean
12
13
14
|
# File 'lib/csv_xlsx_converter/filename.rb', line 12
def self.xlsx_filename? filename
filename =~ RE_XLSX_EXTENSION ? true : false
end
|