class CsvToSqlite::CsvToSQLite
class Error < StandardError; end
Public Class Methods
new(argv)
click to toggle source
# File lib/csv_to_sqlite.rb, line 13 def initialize argv @args = argv end
Public Instance Methods
convert(file_path)
click to toggle source
# File lib/csv_to_sqlite.rb, line 22 def convert file_path connection = CsvToSqlite::Database.new().connect csv_table = CsvToSqlite::CsvReader.new(file_path).load_file CsvToSqlite::SQL::CreateTable.new(name: table_name, csv_table: csv_table, connection: connection).run CsvToSqlite::SQL::Insert.new(name: table_name, csv_table: csv_table, connection: connection).run end
csv_file_name()
click to toggle source
# File lib/csv_to_sqlite.rb, line 38 def csv_file_name file_name = nil @args.each_with_index do |param, index| file_name = param if param.include? ".csv" end file_name end
run()
click to toggle source
# File lib/csv_to_sqlite.rb, line 17 def run method = CsvToSqlite::ArgumentHandlerService.new(@args).call self.convert(@args.first) unless method.nil? end
table_name()
click to toggle source
# File lib/csv_to_sqlite.rb, line 29 def table_name if @args.include? "-t" table_name_index = @args.find_index "-t" return @args[table_name_index + 1] else return csv_file_name.split("/").last.split(".csv").first end end