Module: QuickETL::QuickETLKernel

Included in:
QuickETLObject
Defined in:
lib/quick_etl_kernel.rb

Instance Method Summary collapse

Instance Method Details

#command_line_arg(name, default) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/quick_etl_kernel.rb', line 104

def command_line_arg(name, default)
  value = default
  if name
    value = ENV[name]
  value = default  if value == nil
  end
  value 
end

#command_line_array_arg(name, default) ⇒ Object



120
121
122
123
124
# File 'lib/quick_etl_kernel.rb', line 120

def command_line_array_arg(name, default)
  s = command_line_arg(name, nil)
  return default  if s == nil
  return s.split(',')
end

#command_line_boolean_arg(name, default) ⇒ Object



113
114
115
116
117
118
# File 'lib/quick_etl_kernel.rb', line 113

def command_line_boolean_arg(name, default)
  v = command_line_arg(name, "#{default}")
  return true  if ((v.downcase == 'true') || (v.downcase == 't'))
  return true  if ((v.downcase == 'yes')  || (v.downcase == 'y'))
  false
end

#default_delimiterObject



257
258
259
# File 'lib/quick_etl_kernel.rb', line 257

def default_delimiter
  '|'
end

#display_general_infoObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/quick_etl_kernel.rb', line 62

def display_general_info
  puts ""
  puts "This is '#{project_name}'. " 
  puts "#{project_copyright} " 
  puts "#{project_license} "   
  puts ""
  puts "QuickETL home pages: "
  puts "  -- http://rubyforge.org/projects/quick-etl/ "  
  puts "  -- http://www.joakim-systems.com/ "    
  puts ""
  puts "QuickETL uses the SQLite3 database; see the following URLs: "
  puts "  -- http://www.sqlite.org/"
  puts "  -- http://sqlite-ruby.rubyforge.org/ "
  puts "  -- http://sqlite-ruby.rubyforge.org/sqlite3/faq.html "
  puts ""
  puts "Enter 'rake help' for QuickETL usage instructions. "
  puts "Enter 'rake -T' for the list of available QuickETL rake commands. "  
  puts ""
  
  home = home_dir
  if (home_dir)
    puts "Your QuickETL home directory is currently set to: #{home_dir}"  
  else
    puts "Warning: You have not yet set your 'QUICK_ETL_HOME' environment variable."
  end
  puts ""
end

#display_usage_instructionsObject



90
91
92
93
# File 'lib/quick_etl_kernel.rb', line 90

def display_usage_instructions
  puts "usage"
  puts ""
end

#get_array_property(name, default = Array.new) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/quick_etl_kernel.rb', line 133

def get_array_property(name, default=Array.new)
  s = get_property(name)
  if s
    return s.split(',')
  end
  default
end

#get_property(name, default = '') ⇒ Object



126
127
128
129
130
131
# File 'lib/quick_etl_kernel.rb', line 126

def get_property(name, default='')
  if @@properties.has_key? "#{name}"
    return @@properties["#{name}"]
  end
  default
end

#home_dirObject



95
96
97
98
99
100
101
102
# File 'lib/quick_etl_kernel.rb', line 95

def home_dir
  is_dev = ENV['dev']
  if ((is_dev) && (is_dev == 'y'))
    ENV[QUICK_ETL_DEV_HOME]
  else
    ENV[QUICK_ETL_HOME]
  end
end

#line_value(s) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/quick_etl_kernel.rb', line 237

def line_value(s)
  if ((s == nil) || (s.size < 1))
    s
  else
    s[1, s.size]
  end
end

#load_properties(properties_filename) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/quick_etl_kernel.rb', line 145

def load_properties(properties_filename)
  props = Hash.new
  if File.exist? properties_filename
    File.open(properties_filename, 'r') do | properties_file |
      properties_file.read.each_line do |line|
        line.strip!
        if (line[0] != ?# and line[0] != ?=)
          i = line.index('=')
          if (i)
            props[line[0..i - 1].strip] = line[i + 1..-1].strip
          else
            props[line] = ''
          end
        end
      end
      puts "properties file read - #{properties_filename} , entry count=#{props.size}"  if true
    end
  else
    puts "properties file does not exist - #{properties_filename}"  if false
  end
  @@properties = props
end

#parse_qif_filesObject



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/quick_etl_kernel.rb', line 168

def parse_qif_files
  qif_file = command_line_arg('qif', QuickETL::DEFAULT_QIF_FILE)
  qif_dir  = get_property('qif_dir', home_dir)
  qif_path = "#{qif_dir}/#{qif_file}"
  owner  = command_line_arg('owner', 'owner')      
  reader = QuickETL::QifFileReader.new(owner, qif_path)
  array  = Array.new
  reader.transactions.each_with_index { | tran, idx| 
    array << "#{idx+1}#{tran.to_s}"  
  }  
  write_lines("#{home_dir}/quick-etl.csv", array)
end

#project_authorObject



42
43
44
# File 'lib/quick_etl_kernel.rb', line 42

def project_author
  'Chris Joakim'
end


50
51
52
# File 'lib/quick_etl_kernel.rb', line 50

def project_copyright
  "Copyright (C) #{project_year} #{project_author}"
end

#project_dateObject



38
39
40
# File 'lib/quick_etl_kernel.rb', line 38

def project_date       
  '2008/02/10'
end

#project_embedded_commentObject



54
55
56
# File 'lib/quick_etl_kernel.rb', line 54

def project_embedded_comment
  "#{project_name} #{project_version_number}"
end

#project_licenseObject



58
59
60
# File 'lib/quick_etl_kernel.rb', line 58

def project_license    
  'GNU General Public License (GPL).  See http://www.gnu.org/copyleft/gpl.html'
end

#project_nameObject



30
31
32
# File 'lib/quick_etl_kernel.rb', line 30

def project_name
  'QuickETL'
end

#project_version_numberObject



34
35
36
# File 'lib/quick_etl_kernel.rb', line 34

def project_version_number   
  '0.1.0'
end

#project_yearObject



46
47
48
# File 'lib/quick_etl_kernel.rb', line 46

def project_year       
  project_date[0...4]  # start, length
end

#read_as_ascii_lines(filename, delim = 10, strip = false) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/quick_etl_kernel.rb', line 201

def read_as_ascii_lines(filename, delim=10, strip=false)  
  array = Array.new  
  file  = File.new(filename)
  currLine = ''
  bytesRead = 0
  linesRead = 0
  
  file.each_byte { |b| 
    bytesRead = bytesRead + 1
    if (b == delim) # delim is 13 for quicken, 10 for address book xml
      array << currLine
      currLine = ''
      linesRead = linesRead + 1
    else
      if (b < 127)
        currLine << "#{b.chr}"
      end
    end  
  }
  if currLine.size > 0
    array << currLine
  end
  if strip
    array = strip_lines(array)
  end
  array    
end

#read_lines(filename, strip = false) ⇒ Object



181
182
183
184
185
# File 'lib/quick_etl_kernel.rb', line 181

def read_lines(filename, strip=false)  
  array = IO.readlines(filename)
  array = strip_lines(array)  if strip
  array
end

#startupObject



141
142
143
# File 'lib/quick_etl_kernel.rb', line 141

def startup
  load_properties("#{home_dir}/#{QuickETL::PROPERTIES_FILE}") 
end

#strip_lines(array) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/quick_etl_kernel.rb', line 229

def strip_lines(array)  
  newArray = Array.new
  if (array != nil)
    array.each { |line| line.strip! ; newArray << line }
  end
  newArray
end

#tokenize(string, delim = nil, strip = false) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/quick_etl_kernel.rb', line 245

def tokenize(string, delim=nil, strip=false)  
  if string
    tokens = string.split(delim)
    if strip
      tokens.each { |tok| tok.strip! }
    end
    tokens
  else
    Array.new
  end
end

#usage_instructionsObject



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/quick_etl_kernel.rb', line 261

def usage_instructions
  s = <<HERE
  
1.  Use your Quicken program to export its data to the QUICK_ETL_HOME directory.
Specify output file 'QuickenData.qif'.

2.  Open a shell window in your QUICK_ETL_HOME directory.

Execute command 'rake -T' to see the list of functions available.

Execute command 'rake parse' to parse the qif file into csv format.

Execute command 'rake load' to load the csv file data into sqlite3 database 'quick-etl.db'.

Execute command 'rake parse_and_load' to run both the parsing and loading function.

Execute command 'rake show_ddl' to see the structure of the database table and its column names.
    
3.  Use the sqlite3 CLP (Command Line Program) to query the database.
From the QUICK_ETL_HOME directory, execute command 'sqlite3 quick-etl.db'.

You can then enter and execute queries like the following:

sqlite> select * from transactions;
sqlite> select * from transactions where tran_date == '2008-02-05';

Note: A User Interface will be created for QuickETL its next release.    
    
HERE
  s
end

#write_file(out_name, content) ⇒ Object



187
188
189
190
191
192
193
# File 'lib/quick_etl_kernel.rb', line 187

def write_file(out_name, content)
  out = File.new out_name, "w+"
  out.write content
  out.flush
  out.close  
  puts "file written: #{out_name}"  
end

#write_lines(out_name, lines) ⇒ Object



195
196
197
198
199
# File 'lib/quick_etl_kernel.rb', line 195

def write_lines(out_name, lines)
  s = ''
  lines.each { | line | s << "#{line}\n" }
  write_file(out_name, s)
end