Class: TextFerry::Loader
- Inherits:
-
Object
- Object
- TextFerry::Loader
- Defined in:
- lib/text_ferry/loader.rb
Overview
Loads CSV data into a database.
Instance Method Summary collapse
-
#initialize(database_uri, data_path) ⇒ Loader
constructor
- database_uri
-
A URI that points to a database.
-
#load_table(table_name, &schema) ⇒ Object
Loads data from a CSV file into the database.
Constructor Details
#initialize(database_uri, data_path) ⇒ Loader
- database_uri
-
A URI that points to a database. See sequel.rubyforge.org/rdoc/classes/Sequel.html#method-c-connect for more info.
- data_path
-
The full path to a folder that contains one or more CSV files.
14 15 16 17 |
# File 'lib/text_ferry/loader.rb', line 14 def initialize(database_uri, data_path) @db = Sequel.connect(database_uri) @data_path = data_path end |
Instance Method Details
#load_table(table_name, &schema) ⇒ Object
Loads data from a CSV file into the database. Assumes that table_name
corresponds to a CSV file in data_path
. Warning: if the table already exists, it will be dropped!
- table_name
-
The name of the CSV file to load; will also be used as the table name in the database.
- schema
-
A block that specifies the schema of the CSV file / table. See sequel.rubyforge.org/rdoc/files/doc/schema_modification_rdoc.html for more info.
31 32 33 34 |
# File 'lib/text_ferry/loader.rb', line 31 def load_table(table_name, &schema) @db.create_table!(table_name, &schema) load_data(table_name) end |