reckon 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # Changes
2
2
 
3
+ * 6/26/13 - Multi-currency support contributed by @zebh.
4
+ * 4/27/13 - Add --account commandline option
3
5
  * 3/24/13 - Force encoding to UTF-8 when unknown characters are encountered.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reckon (0.3.6)
4
+ reckon (0.3.7)
5
5
  chronic (>= 0.3.0)
6
6
  fastercsv (>= 1.5.1)
7
7
  highline (>= 1.5.2)
@@ -13,7 +13,7 @@ GEM
13
13
  chronic (0.9.1)
14
14
  diff-lcs (1.1.3)
15
15
  fastercsv (1.5.5)
16
- highline (1.6.18)
16
+ highline (1.6.19)
17
17
  rake (10.0.4)
18
18
  rspec (2.11.0)
19
19
  rspec-core (~> 2.11.0)
@@ -10,6 +10,7 @@ module Reckon
10
10
  self.tokens = {}
11
11
  self.accounts = {}
12
12
  self.seen = {}
13
+ self.options[:currency] ||= '$'
13
14
  learn!
14
15
  parse
15
16
  filter_csv
@@ -168,7 +169,12 @@ module Reckon
168
169
  end
169
170
 
170
171
  def pretty_money(amount, negate = false)
171
- (amount >= 0 ? " " : "") + sprintf("%0.2f", amount * (negate ? -1 : 1)).gsub(/^((\-)|)(?=\d)/, '\1$')
172
+ currency = options[:currency]
173
+ if options[:suffixed]
174
+ (amount >= 0 ? " " : "") + sprintf("%0.2f #{currency}", amount * (negate ? -1 : 1))
175
+ else
176
+ (amount >= 0 ? " " : "") + sprintf("%0.2f", amount * (negate ? -1 : 1)).gsub(/^((\-)|)(?=\d)/, "\\1#{currency}")
177
+ end
172
178
  end
173
179
 
174
180
  def date_for(index)
@@ -359,6 +365,10 @@ module Reckon
359
365
  options[:file] = file
360
366
  end
361
367
 
368
+ opts.on("-a", "--account name", "The Ledger Account this file is for") do |a|
369
+ options[:bank_account] = a
370
+ end
371
+
362
372
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
363
373
  options[:verbose] = v
364
374
  end
@@ -399,6 +409,14 @@ module Reckon
399
409
  options[:encoding] = e
400
410
  end
401
411
 
412
+ opts.on("-c", "--currency", "Currency symbol to use, defaults to $. ex.) $, EUR") do |e|
413
+ options[:currency] = e
414
+ end
415
+
416
+ opts.on("", "--suffixed", "If --currency should be used as a suffix. Defaults to false.") do |e|
417
+ options[:suffixed] = e
418
+ end
419
+
402
420
  opts.on_tail("-h", "--help", "Show this message") do
403
421
  puts opts
404
422
  exit
@@ -18,7 +18,7 @@ module Reckon
18
18
  accounts = []
19
19
  ledger.strip.split("\n").each do |entry|
20
20
  next if entry =~ /^\s*$/ || entry =~ /^[^ \t\d]/
21
- if entry =~ /^([\d\/]+)(\=[\d\/]+)?(\s+[\*!]?\s*.*?)$/
21
+ if entry =~ /^([\d\/-]+)(\=[\d\/-]+)?(\s+[\*!]?\s*.*?)$/
22
22
  @entries << { :date => date.strip, :desc => desc.strip, :accounts => balance(accounts) } if date
23
23
  date = $1
24
24
  desc = $3
@@ -56,7 +56,7 @@ module Reckon
56
56
 
57
57
  def clean_money(money)
58
58
  return nil if money.nil? || money.length == 0
59
- money.gsub(/[\$,]/, '').to_f
59
+ money.gsub(/[^0-9.-]/, '').to_f
60
60
  end
61
61
  end
62
62
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{reckon}
6
- s.version = "0.3.6"
6
+ s.version = "0.3.7"
7
7
  s.authors = ["Andrew Cantino"]
8
8
  s.email = %q{andrew@iterationlabs.com}
9
9
  s.homepage = %q{https://github.com/cantino/reckon}
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  require "spec_helper"
4
5
  require 'rubygems'
@@ -158,6 +159,24 @@ describe Reckon::App do
158
159
  @some_other_bank.pretty_money_for(5).should == " $0.23"
159
160
  @some_other_bank.pretty_money_for(6).should == "-$0.96"
160
161
  end
162
+
163
+ it "work with other currencies such as €" do
164
+ euro_bank = Reckon::App.new(:string => SOME_OTHER_CSV, :currency => "€", :suffixed => false )
165
+ euro_bank.pretty_money_for(1).should == "-€20.00"
166
+ euro_bank.pretty_money_for(4).should == " €1558.52"
167
+ euro_bank.pretty_money_for(7).should == "-€116.22"
168
+ euro_bank.pretty_money_for(5).should == " €0.23"
169
+ euro_bank.pretty_money_for(6).should == "-€0.96"
170
+ end
171
+
172
+ it "work with suffixed currencies such as SEK" do
173
+ swedish_bank = Reckon::App.new(:string => SOME_OTHER_CSV, :currency => 'SEK', :suffixed => true )
174
+ swedish_bank.pretty_money_for(1).should == "-20.00 SEK"
175
+ swedish_bank.pretty_money_for(4).should == " 1558.52 SEK"
176
+ swedish_bank.pretty_money_for(7).should == "-116.22 SEK"
177
+ swedish_bank.pretty_money_for(5).should == " 0.23 SEK"
178
+ swedish_bank.pretty_money_for(6).should == "-0.96 SEK"
179
+ end
161
180
  end
162
181
 
163
182
  describe "merge_columns" do
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ #encoding: utf-8
2
3
 
3
4
  require "spec_helper"
4
5
  require 'rubygems'
@@ -12,12 +13,12 @@ describe Reckon::LedgerParser do
12
13
 
13
14
  describe "parse" do
14
15
  it "should ignore non-standard entries" do
15
- @ledger.entries.length.should == 5
16
+ @ledger.entries.length.should == 7
16
17
  end
17
18
 
18
19
  it "should parse entries correctly" do
19
20
  @ledger.entries.first[:desc].should == "* Checking balance"
20
- @ledger.entries.first[:date].should == "2004/05/01"
21
+ @ledger.entries.first[:date].should == "2004-05-01"
21
22
  @ledger.entries.first[:accounts].first[:name].should == "Assets:Bank:Checking"
22
23
  @ledger.entries.first[:accounts].first[:amount].should == 1000
23
24
  @ledger.entries.first[:accounts].last[:name].should == "Equity:Opening Balances"
@@ -72,10 +73,18 @@ describe Reckon::LedgerParser do
72
73
  Assets:Bank:Checking $500.00
73
74
  Income:Salary
74
75
 
75
- 2004/05/01 * Checking balance
76
+ 2004-05-01 * Checking balance
76
77
  Assets:Bank:Checking $1,000.00
77
78
  Equity:Opening Balances
78
79
 
80
+ 2004-05-01 * Checking balance
81
+ Assets:Bank:Checking €1,000.00
82
+ Equity:Opening Balances
83
+
84
+ 2004-05-01 * Checking balance
85
+ Assets:Bank:Checking 1,000.00 SEK
86
+ Equity:Opening Balances
87
+
79
88
  2004/05/01 * Investment balance
80
89
  Assets:Brokerage 50 AAPL @ $30.00
81
90
  Equity:Opening Balances
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reckon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 3416374461755206032
139
+ hash: 989806142141775865
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 3416374461755206032
148
+ hash: 989806142141775865
149
149
  requirements: []
150
150
  rubyforge_project:
151
151
  rubygems_version: 1.8.25