reckon 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Changes
2
2
 
3
+ * 7/02/13 - Customizable date parsing contributed by @mauromorales.
3
4
  * 6/26/13 - Multi-currency support contributed by @zebh.
4
5
  * 4/27/13 - Add --account commandline option
5
6
  * 3/24/13 - Force encoding to UTF-8 when unknown characters are encountered.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reckon (0.3.7)
4
+ reckon (0.3.8)
5
5
  chronic (>= 0.3.0)
6
6
  fastercsv (>= 1.5.1)
7
7
  highline (>= 1.5.2)
data/lib/reckon/app.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #coding: utf-8
1
2
  require 'pp'
2
3
 
3
4
  module Reckon
@@ -179,16 +180,25 @@ module Reckon
179
180
 
180
181
  def date_for(index)
181
182
  value = columns[date_column_index][index]
182
- value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})\d+\[\d+\:GMT\]$/ # chase format
183
- value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\.(\d{2})\.(\d{4})$/ # german format
184
- value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\-(\d{2})\-(\d{4})$/ # nordea format
185
- value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})/ # yyyymmdd format
186
- begin
187
- guess = Chronic.parse(value, :context => :past)
188
- if guess.to_i < 953236800 && value =~ /\//
189
- guess = Chronic.parse((value.split("/")[0...-1] + [(2000 + value.split("/").last.to_i).to_s]).join("/"), :context => :past)
183
+ if options[:date_format].nil?
184
+ value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})\d+\[\d+\:GMT\]$/ # chase format
185
+ value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\.(\d{2})\.(\d{4})$/ # german format
186
+ value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\-(\d{2})\-(\d{4})$/ # nordea format
187
+ value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})/ # yyyymmdd format
188
+ else
189
+ begin
190
+ value = Date.strptime(value, options[:date_format])
191
+ rescue
192
+ puts "I'm having trouble parsing #{value} with the desired format: #{options[:date_format]}"
193
+ exit 1
190
194
  end
191
- guess
195
+ end
196
+ begin
197
+ guess = Chronic.parse(value, :context => :past)
198
+ if guess.to_i < 953236800 && value =~ /\//
199
+ guess = Chronic.parse((value.split("/")[0...-1] + [(2000 + value.split("/").last.to_i).to_s]).join("/"), :context => :past)
200
+ end
201
+ guess
192
202
  rescue
193
203
  puts "I'm having trouble parsing #{value}, which I thought was a date. Please report this so that we"
194
204
  puts "can make this parser better!"
@@ -409,10 +419,14 @@ module Reckon
409
419
  options[:encoding] = e
410
420
  end
411
421
 
412
- opts.on("-c", "--currency", "Currency symbol to use, defaults to $. ex.) $, EUR") do |e|
422
+ opts.on("-c", "--currency '$'", "Currency symbol to use, defaults to $ (£, EUR)") do |e|
413
423
  options[:currency] = e
414
424
  end
415
425
 
426
+ opts.on("", "--date-format '%d/%m/%Y'", "Force the date format (see Ruby DateTime strftime)") do |d|
427
+ options[:date_format] = d
428
+ end
429
+
416
430
  opts.on("", "--suffixed", "If --currency should be used as a suffix. Defaults to false.") do |e|
417
431
  options[:suffixed] = e
418
432
  end
data/reckon.gemspec CHANGED
@@ -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.7"
6
+ s.version = "0.3.8"
7
7
  s.authors = ["Andrew Cantino"]
8
8
  s.email = %q{andrew@iterationlabs.com}
9
9
  s.homepage = %q{https://github.com/cantino/reckon}
@@ -16,6 +16,8 @@ describe Reckon::App do
16
16
  @german_date = Reckon::App.new(:string => GERMAN_DATE_EXAMPLE)
17
17
  @danish_kroner_nordea = Reckon::App.new(:string => DANISH_KRONER_NORDEA_EXAMPLE, :csv_separator => ';', :comma_separates_cents => true)
18
18
  @yyyymmdd_date = Reckon::App.new(:string => YYYYMMDD_DATE_EXAMPLE)
19
+ @spanish_date = Reckon::App.new(:string => SPANISH_DATE_EXAMPLE, :date_format => '%d/%m/%Y')
20
+ @english_date = Reckon::App.new(:string => ENGLISH_DATE_EXAMPLE)
19
21
  end
20
22
 
21
23
  it "should be in testing mode" do
@@ -141,6 +143,12 @@ describe Reckon::App do
141
143
  @yyyymmdd_date.date_for(0).year.should == Time.parse("2012/12/31").year
142
144
  @yyyymmdd_date.date_for(0).month.should == Time.parse("2012/12/31").month
143
145
  @yyyymmdd_date.date_for(0).day.should == Time.parse("2012/12/31").day
146
+ @spanish_date.date_for(1).year.should == Time.parse("2009/12/02").year
147
+ @spanish_date.date_for(1).month.should == Time.parse("2009/12/02").month
148
+ @spanish_date.date_for(1).day.should == Time.parse("2009/12/02").day
149
+ @english_date.date_for(1).year.should == Time.parse("2009/12/24").year
150
+ @english_date.date_for(1).month.should == Time.parse("2009/12/24").month
151
+ @english_date.date_for(1).day.should == Time.parse("2009/12/24").day
144
152
  end
145
153
  end
146
154
 
@@ -271,4 +279,16 @@ describe Reckon::App do
271
279
  DEBIT,20121231,"ODESK***BAL-27DEC12 650-12345 CA 12/28",-123.45
272
280
  CSV
273
281
 
282
+ SPANISH_DATE_EXAMPLE = (<<-CSV).strip
283
+ 02/12/2009,Check - 0000000122,122,-$76.00,"","$1,750.06"
284
+ 02/12/2009,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
285
+ 02/12/2009,Check - 0000000112,112,-$800.00,"","$1,498.57"
286
+ CSV
287
+
288
+ ENGLISH_DATE_EXAMPLE = (<<-CSV).strip
289
+ 24/12/2009,Check - 0000000122,122,-$76.00,"","$1,750.06"
290
+ 24/12/2009,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
291
+ 24/12/2009,Check - 0000000112,112,-$800.00,"","$1,498.57"
292
+ CSV
293
+
274
294
  end
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.7
4
+ version: 0.3.8
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-06-27 00:00:00.000000000 Z
12
+ date: 2013-07-03 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: 989806142141775865
139
+ hash: -1602098812968474489
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: 989806142141775865
148
+ hash: -1602098812968474489
149
149
  requirements: []
150
150
  rubyforge_project:
151
151
  rubygems_version: 1.8.25