Class: SQLite2DBF

Inherits:
Object
  • Object
show all
Includes:
Logging, Translating
Defined in:
lib/sqlite2dbf.rb

Overview

The main program class. Does it.

Instance Method Summary collapse

Methods included from Translating

language, trl, #trl

Methods included from Logging

#init_logger, #log_level=, #log_target=

Methods included from File_Checking

#file_check, file_check

Constructor Details

#initialize(*args) ⇒ SQLite2DBF

Returns a new instance of SQLite2DBF.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sqlite2dbf.rb', line 39

def initialize(*args)
  options = ArgParser::parse(args)
  init_logger
  level = (options.debug ? Logger::DEBUG : @log.level)
  @log.level = level 
  @log.debug('options are: ' << options.to_s)

  @date_fields = options.datetime ? options.datetime : []
  @time_fields = options.time ? options.time : []

  if(options.source)
    sqlite_file = options.source  
    dbf_file = options.target if options.target
    dbf_file = :table if options.table_name
    dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*')
    msg = nil
  
    if(dbf_file != :table)
      if(File.exist?(dbf_file))
        msg = File_Checking.file_check(dbf_file, :file, :writable)
      elsif(File.exist?(File.dirname(dbf_file))) 
        msg = File_Checking.file_check(File.dirname(dbf_file), :directory, :writable)
      end
    end

    msg ||= File_Checking.file_check(sqlite_file, :exist, :readable, :file)

    if(!msg)
      @log.debug('will transform ' << sqlite_file << ' to  ' << dbf_file.to_s << '.dbf')
      transform(sqlite_file, dbf_file)
    else
      msg = trl("ERROR! Unsuitable file") << " : %s" %msg
      @log.error(msg)
      exit false
    end
  else
    puts trl("ERROR! Source-file is a mandatory program parameter!")
    puts trl("Start this program with parameter -h or --help to see the usage-message.")  
  end

end