lib/reckon/app.rb in reckon-0.3.1 vs lib/reckon/app.rb in reckon-0.3.2

- old
+ new

@@ -1,5 +1,7 @@ +require 'pp' + module Reckon class App VERSION = "Reckon 0.1" attr_accessor :options, :csv_data, :accounts, :tokens, :money_column_indices, :date_column_index, :description_column_indices, :seen @@ -169,10 +171,11 @@ end def date_for(index) value = columns[date_column_index][index] value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})\d+\[\d+\:GMT\]$/ # chase format + value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\.(\d{2})\.(\d{4})$/ # chase format begin guess = Chronic.parse(value, :context => :past) if guess.to_i < 953236800 && value =~ /\// guess = Chronic.parse((value.split("/")[0...-1] + [(2000 + value.split("/").last.to_i).to_s]).join("/"), :context => :past) end @@ -224,11 +227,11 @@ date_score += 30 if entry =~ /^\d+[:\/\.]\d+[:\/\.]\d+([ :]\d+[:\/\.]\d+)?$/ date_score += 10 if entry =~ /^\d+\[\d+:GMT\]$/i # Try to determine if this is a balance column entry_as_num = entry.gsub(/[^\-\d\.]/, '').to_f - if last && entry_as_num != 0 && last != 0 + if last && entry_as_num != 0 && last != 0 row.each do |row_entry| row_entry = row_entry.to_s.gsub(/[^\-\d\.]/, '').to_f if row_entry != 0 && last + row_entry == entry_as_num money_score -= 10 break @@ -265,11 +268,10 @@ end end output_columns end - require 'pp' def detect_columns results, found_likely_money_column = evaluate_columns(columns) self.money_column_indices = [ results.sort { |a, b| b[:money_score] <=> a[:money_score] }.first[:index] ] if !found_likely_money_column @@ -285,11 +287,11 @@ puts "please report this issue to us so we can take a look!\n" end break end end - + if !found_likely_double_money_columns && !settings[:testing] puts "I didn't find a high-likelyhood money column, but I'm taking my best guess with column #{money_column_indices.first + 1}." end end @@ -329,11 +331,13 @@ end end def parse data = options[:string] || File.read(options[:file]) - self.csv_data = (RUBY_VERSION =~ /^1\.9/ ? CSV : FasterCSV).parse(data.strip, :col_sep => options[:csv_separator] || ',') + @csv_data = (RUBY_VERSION =~ /^1\.9/ ? CSV : FasterCSV).parse(data.strip, :col_sep => options[:csv_separator] || ',') + csv_data.shift if options[:contains_header] + csv_data end def self.parse_opts(args = ARGV) options = { :output_file => STDOUT } parser = OptionParser.new do |opts| @@ -362,11 +366,15 @@ opts.on("", "--ignore-columns 1,2,5", "Columns to ignore in the CSV file - the first column is column 1") do |ignore| options[:ignore_columns] = ignore.split(",").map { |i| i.to_i } end - opts.on("", "--csv-separator ';'", "Separator for parsing the CSV - default is comma.") do |csv_separator| + opts.on("", "--contains-header", "The first row of the CSV is a header and should be skipped") do |contains_header| + options[:contains_header] = contains_header + end + + opts.on("", "--csv-separator ','", "Separator for parsing the CSV - default is comma.") do |csv_separator| options[:csv_separator] = csv_separator end opts.on("", "--comma-separates-cents", "Use comma instead of period to deliminate dollars from cents when parsing ($100,50 instead of $100.50)") do |c| options[:comma_separates_cents] = c @@ -407,12 +415,11 @@ @settings = { :testing => false } def self.settings @settings end - + def settings self.class.settings end end end - \ No newline at end of file