Class: CSVToSqlite::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, table_name = nil, column_names = nil) ⇒ Parser

Returns a new instance of Parser.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/csv_to_sqlite/parser.rb', line 14

def initialize(source, target, table_name=nil, column_names=nil)
  if File.exists?(source)
    @source = IO.readlines(source).to_s
  else
    @source = source
  end
  
  @target = target
  @table_name = table_name || 'item'
  @column_names = column_names || _name_columns(@source)
  
  _connect(@target)
  _create_model(@table_name, @column_names)
  
  DataMapper.finalize
  DataMapper.auto_migrate!
end

Instance Attribute Details

#column_namesObject (readonly)

Returns the value of attribute column_names.



12
13
14
# File 'lib/csv_to_sqlite/parser.rb', line 12

def column_names
  @column_names
end

#dbObject (readonly)

Returns the value of attribute db.



10
11
12
# File 'lib/csv_to_sqlite/parser.rb', line 10

def db
  @db
end

#klassObject (readonly)

Returns the value of attribute klass.



11
12
13
# File 'lib/csv_to_sqlite/parser.rb', line 11

def klass
  @klass
end

Instance Method Details

#parse!Object



32
33
34
# File 'lib/csv_to_sqlite/parser.rb', line 32

def parse!
  _parse(@source)
end