module CsvXlsxConverter

Constants

RE_CSV_EXTENSION
RE_XLSX_EXTENSION

Public Class Methods

csv_filename?(filename) click to toggle source
# File lib/csv_xlsx_converter/filename.rb, line 8
def self.csv_filename? filename
  filename =~ RE_CSV_EXTENSION ? true : false
end
handle_in(param) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/csv_xlsx_converter/filename.rb, line 12
def self.xlsx_filename? filename
  filename =~ RE_XLSX_EXTENSION ? true : false
end