Class: Database
- Inherits:
-
Object
- Object
- Database
- Defined in:
- lib/csvr/sqlitedb.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(db, table, headers, rows) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(db, table, headers, rows) ⇒ Database
Returns a new instance of Database.
7 8 9 10 11 12 |
# File 'lib/csvr/sqlitedb.rb', line 7 def initialize(db, table, headers, rows) @db = db @table = table @headers = headers @rows = rows end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/csvr/sqlitedb.rb', line 5 def db @db end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/csvr/sqlitedb.rb', line 5 def headers @headers end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/csvr/sqlitedb.rb', line 5 def rows @rows end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
5 6 7 |
# File 'lib/csvr/sqlitedb.rb', line 5 def table @table end |
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/csvr/sqlitedb.rb', line 14 def create puts "Inserting #{@rows.size} rows into database" db = SQLite3::Database.open("#{@db}.db") db.execute "CREATE TABLE IF NOT EXISTS #{@table}(#{@headers})" @rows.each { |row| db.execute "INSERT INTO #{@table} #{row}" } db.close end |