class CSVToSqlite::Runner

Attributes

arguments[R]
argv[R]
command[R]
options[R]
parser[R]

Public Class Methods

new(argv) click to toggle source
# File lib/csv_to_sqlite/runner.rb, line 13
def initialize(argv)
  @argv = argv
  @options = {
    :verbose =>     true
  }
  init_parser
end

Public Instance Methods

run() click to toggle source
# File lib/csv_to_sqlite/runner.rb, line 21
def run
  parse!
  CSVToSqlite::Parser.new(@source, @target, @options[:table], @options[:columns]).parse!
end

Protected Instance Methods

init_parser() click to toggle source
# File lib/csv_to_sqlite/runner.rb, line 28
def init_parser
  
  @parser ||= OptionParser.new do |opts|
    opts.banner = "Usage: csv_to_sqlite [OPTIONS] source target"
    opts.separator ""
    opts.on('-t', '--table TABLE_NAME', 'The name of the table to create in the database.')                   { |table| @options[:table] = table }
    opts.on('-c', '--columns COLUMN_NAMES', 'Comma separated list of column names. Ex: one,two,three...')     { |columns| @options[:columns] = columns.split(',') }
    opts.on('-q', '--quiet')                                                                                  { |quiet| @options[:verbose] = false }
    opts.on('-v', '--version')                                                                                { puts version ; exit }
    opts.on('-h', '--help')                                                                                   { puts opts ; exit }
    opts.on("-D", "--debug", "Set debugging on")                                                              { @options[:debug] = true }
    opts.separator ""
  end
  
end
parse!() click to toggle source
# File lib/csv_to_sqlite/runner.rb, line 44
def parse!
  
  begin
    @parser.parse!(@argv)
  rescue
    puts @parser.help
    exit 1
  end
  
  @source = @argv.shift
  
  if @source.nil?
    puts @parser.help
    exit 1
  end
  
  @target = @argv.shift
  
  if @target.nil?
    puts @parser.help
    exit 1
  end
  
  @arguments = @argv

end
version() click to toggle source
# File lib/csv_to_sqlite/runner.rb, line 71
def version
  "csv_to_sqlite #{GPC::VERSION}"
end