csv_to_sqlite 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/file.sqlite3 ADDED
Binary file
data/lib/csv_to_sqlite.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module CSVToSqlite
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../'))
5
5
 
6
6
  autoload :Runner, "#{ROOT}/lib/csv_to_sqlite/runner"
@@ -40,9 +40,7 @@ module CSVToSqlite
40
40
  end
41
41
 
42
42
  def _create_model(table_name, column_names)
43
- @klass = Object.const_set(table_name.capitalize, Class.new)
44
- @klass.class_eval do
45
- include DataMapper::Resource
43
+ @klass = DataMapper::Model.new do
46
44
  property :id, DataMapper::Property::Serial
47
45
  column_names.each do |column|
48
46
  property column.to_s.to_sym, DataMapper::Property::String
@@ -56,7 +54,7 @@ module CSVToSqlite
56
54
  FasterCSV.parse(source) do |row|
57
55
  columns_count = row.length if row.length > columns_count
58
56
  end
59
- (0...columns_count).each {|i| columns.push("col_#{i.to_s}") }
57
+ (0...columns_count).each {|i| columns.push("col_#{i.to_s}")}
60
58
  columns
61
59
  end
62
60
 
@@ -5,10 +5,10 @@ module CSVToSqlite
5
5
  class Runner
6
6
 
7
7
  attr_reader :argv
8
- attr_accessor :parser
9
- attr_accessor :options
10
- attr_accessor :command
11
- attr_accessor :arguments
8
+ attr_reader :parser
9
+ attr_reader :options
10
+ attr_reader :command
11
+ attr_reader :arguments
12
12
 
13
13
  def initialize(argv)
14
14
  @argv = argv
@@ -22,7 +22,7 @@ module CSVToSqlite
22
22
  parse!
23
23
  CSVToSqlite::Parser.new(@source, @target, @options[:table], @options[:columns]).parse!
24
24
  end
25
-
25
+
26
26
  protected
27
27
 
28
28
  def init_parser
@@ -31,7 +31,7 @@ module CSVToSqlite
31
31
  opts.banner = "Usage: csv_to_sqlite [OPTIONS] source target"
32
32
  opts.separator ""
33
33
  opts.on('-t', '--table TABLE_NAME', 'The name of the table to create in the database.') { |table| @options[:table] = table }
34
- opts.on('-c', '--columns COLUMN_NAMES', 'Comma separated list of column names. Ex: one,two,three...') { |columns| @options[:columns] = columns.split(',') }
34
+ opts.on('-c', '--columns COLUMN_NAMES', 'Comma separated list of column names. Ex: one,two,three...') { |columns| @options[:columns] = columns.split(',') }
35
35
  opts.on('-q', '--quiet') { |quiet| @options[:verbose] = false }
36
36
  opts.on('-v', '--version') { puts version ; exit }
37
37
  opts.on('-h', '--help') { puts opts ; exit }
@@ -40,18 +40,30 @@ module CSVToSqlite
40
40
  end
41
41
 
42
42
  end
43
-
43
+
44
44
  def parse!
45
45
 
46
46
  begin
47
47
  @parser.parse!(@argv)
48
48
  rescue
49
- puts @parser
49
+ puts @parser.help
50
50
  exit 1
51
51
  end
52
52
 
53
53
  @source = @argv.shift
54
+
55
+ if @source.nil?
56
+ puts @parser.help
57
+ exit 1
58
+ end
59
+
54
60
  @target = @argv.shift
61
+
62
+ if @target.nil?
63
+ puts @parser.help
64
+ exit 1
65
+ end
66
+
55
67
  @arguments = @argv
56
68
 
57
69
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_to_sqlite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - A.C. Wright
@@ -59,6 +59,7 @@ extra_rdoc_files: []
59
59
 
60
60
  files:
61
61
  - bin/csv_to_sqlite
62
+ - bin/file.sqlite3
62
63
  - lib/csv_to_sqlite/parser.rb
63
64
  - lib/csv_to_sqlite/runner.rb
64
65
  - lib/csv_to_sqlite.rb