Class: CsvToSqlite::CsvToSQLite
- Inherits:
-
Object
- Object
- CsvToSqlite::CsvToSQLite
- Defined in:
- lib/csv_to_sqlite.rb
Overview
class Error < StandardError; end
Instance Method Summary collapse
- #convert(file_path) ⇒ Object
- #csv_file_name ⇒ Object
-
#initialize(argv) ⇒ CsvToSQLite
constructor
A new instance of CsvToSQLite.
- #run ⇒ Object
- #table_name ⇒ Object
Constructor Details
#initialize(argv) ⇒ CsvToSQLite
Returns a new instance of CsvToSQLite.
13 14 15 |
# File 'lib/csv_to_sqlite.rb', line 13 def initialize argv @args = argv end |
Instance Method Details
#convert(file_path) ⇒ Object
22 23 24 25 26 27 |
# 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 ⇒ Object
38 39 40 41 42 43 44 |
# 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 ⇒ Object
17 18 19 20 |
# 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 ⇒ Object
29 30 31 32 33 34 35 36 |
# 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 |