Class: CsvToSqlite::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(db_name: "data.sqlite3") ⇒ Database

Returns a new instance of Database.



6
7
8
9
10
# File 'lib/database.rb', line 6

def initialize db_name: "data.sqlite3"
  @db_name = db_name
  @target_dir = target_dir
  @database_path = "#{@target_dir}/#{@db_name}"
end

Instance Method Details

#connectObject



21
22
23
24
# File 'lib/database.rb', line 21

def connect
  create
  SQLite3::Database.new @database_path
end

#createObject



12
13
14
15
16
17
18
19
# File 'lib/database.rb', line 12

def create
  if File.exist? @database_path
    puts "Database found"
  else
    puts "Creating database"
    SQLite3::Database.new @database_path
  end
end