volksbanker 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## 1.0.2 (8 October 2012)
5
+
6
+ * Only show recipient/payer if present.
7
+ * More robust handling of line breaks.
8
+ * Handle variable length headers.
9
+
10
+
4
11
  ## 1.0.1 (30 August 2012)
5
12
 
6
13
  * Include payer in output description.
@@ -11,10 +11,18 @@ module Volksbanker
11
11
  $stderr.puts "Skipping non-EUR currency line item: #{vli.inspect}"
12
12
  next
13
13
  end
14
- ali = AmexLineItem.new vli.posting_date, vli.value, "#{vli.description} (#{vli.recipient_or_payer})"
14
+ ali = AmexLineItem.new vli.posting_date, vli.value, description_for(vli)
15
15
  CSV { |out| out << [ali.date, ali.amount, ali.description] }
16
16
  end
17
17
  end
18
+
19
+ private
20
+
21
+ def self.description_for(volksbank_line_item)
22
+ desc = volksbank_line_item.description
23
+ desc += " (#{volksbank_line_item.recipient_or_payer})" unless volksbank_line_item.recipient_or_payer.nil?
24
+ desc
25
+ end
18
26
  end
19
27
 
20
28
  end
@@ -1,3 +1,3 @@
1
1
  module Volksbanker
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  # Volksbank format line by line:
2
2
  #
3
- # Lines 1-13: header
3
+ # Header information including blank lines.
4
4
  # Subsequent non-blank lines: semi-colon separated values
5
5
  # posting date
6
6
  # value date
@@ -11,7 +11,7 @@
11
11
  # description
12
12
  # currency
13
13
  # amount
14
- # credit (H) /debit (S)
14
+ # credit (H) / debit (S)
15
15
  # Blank line
16
16
  # Footer (opening and closing balances)
17
17
 
@@ -30,30 +30,41 @@ module Volksbanker
30
30
  data = File.open(@file,'r:iso-8859-1:utf-8') { |f| f.read }
31
31
  data = clean_line_breaks data
32
32
 
33
- line_number = 0
33
+ header = true
34
34
  data.each_line do |line|
35
- line_number += 1 # 1-based line numbering
36
- next if line_number <= 13 # skip header
35
+ # skip header
36
+ if line =~ /^"Buchungstag";"Valuta";/ # final line of header
37
+ header = false
38
+ next
39
+ end
40
+ next if header
41
+
37
42
  line.chomp!
38
- break if line.empty? # skip footer
43
+ break if line.empty? # stop before footer
39
44
 
40
- yield VolksbankLineItem.new_from_csv line
45
+ yield VolksbankLineItem.new_from_csv line rescue $stderr.puts "Problem with #{line}: #{$!}"
41
46
  end
42
47
  end
43
48
 
44
49
  private
45
50
 
46
51
  def clean_line_breaks(str)
47
- # Format uses \r\n for line breaks between inter-line breaks and \n for intra-line breaks.
52
+ # Format uses CRLF (\r\n) for line breaks and LF (\n) for intra-line breaks (whatever
53
+ # they are).
48
54
  # There must be a neat Ruby way to do this...
49
- remove_inter_line_breaks remove_intra_line_breaks(str)
55
+ unixify_line_breaks remove_intra_line_breaks(str)
50
56
  end
51
57
 
52
58
  def remove_intra_line_breaks(str)
53
- str.gsub /([^\r])\n/, '\1 '
59
+ # Replace LF, but not CRLF, with space.
60
+ str.
61
+ gsub(/^\n/, ' '). # a line beginning with a LF character
62
+ gsub(/([^\r])\n/, '\1 '). # a non-CR character followed by a LF character
63
+ squeeze(' ')
54
64
  end
55
65
 
56
- def remove_inter_line_breaks(str)
66
+ def unixify_line_breaks(str)
67
+ # Replace CRLF with LF.
57
68
  str.gsub "\r\n", "\n"
58
69
  end
59
70
  end
data/test/cli_test.rb CHANGED
@@ -22,4 +22,12 @@ class CliTest < MiniTest::Unit::TestCase
22
22
  assert_match /Skipping/, err
23
23
  end
24
24
 
25
+ def test_handles_line_feed_shenanigans
26
+ out, err = capture_io do
27
+ Volksbanker::Cli.run fixture('newlines.csv')
28
+ end
29
+
30
+ assert_equal '', err
31
+ end
32
+
25
33
  end
@@ -0,0 +1,19 @@
1
+ "Volksbank Rhein-Wehra eG"
2
+
3
+ "Umsatzanzeige"
4
+
5
+ "BLZ:";"68490000";;"Datum:";"08.10.2012"
6
+ "Konto:";"44318105";;"Uhrzeit:";"10:33:22"
7
+ "Abfrage von:";"Andrew Stewart";;"Kontoinhaber:";"Foo GmbH"
8
+
9
+ "Zeitraum:";"1 Woche";"von:";;"bis:";
10
+ "Betrag in EUR:";;"von:";" ";"bis:";" "
11
+ "Sortiert nach:";"Buchungstag";"absteigend"
12
+
13
+ "Buchungstag";"Valuta";"Auftraggeber/Zahlungsempf�nger";"Empf�nger/Zahlungspflichtiger";"Konto-Nr.";"BLZ";"Vorgang/Verwendungszweck";"W�hrung";"Umsatz";" "
14
+ "02.10.2012";"30.09.2012";;;;;"Abschluss
15
+
16
+ ABSCHLUSS PER 30.09.2012";"EUR";"10,27";"S"
17
+
18
+ "01.10.2012";;;;;;"EUR";"Anfangssaldo";"1.234,56";"H"
19
+ "05.10.2012";;;;;;"EUR";"Endsaldo";"3.456,67";"H"
@@ -1,4 +1,4 @@
1
- 08/08/2012,-7.5,Bankcard-Gebühr FOLGE-NR. 0 VERFALL 12.15 PREIS BEZAHLT BIS 12.2012 (PREIS VR-BANKCARD)
1
+ 08/08/2012,-7.5,Bankcard-Gebühr FOLGE-NR. 0 VERFALL 12.15 PREIS BEZAHLT BIS 12.2012 (PREIS VR-BANKCARD)
2
2
  08/08/2012,170.0,Vergütung INVOICE 7004 (Jane Doe)
3
3
  07/08/2012,170.0,"Vergütung INVOICE 7003 Acme GmbH, JULY 2012 (Sarah Smith)"
4
4
  03/08/2012,2023.0,Vergütung INVOICE 7002 (Some Firm GmbH)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volksbanker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2155443660 !ruby/object:Gem::Requirement
16
+ requirement: &2164669360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2155443660
24
+ version_requirements: *2164669360
25
25
  description: Prepares Volksbank's electronic statements for upload to Freeagent.
26
26
  email:
27
27
  - boss@airbladesoftware.com
@@ -43,6 +43,7 @@ files:
43
43
  - lib/volksbanker/volksbank_file_reader.rb
44
44
  - lib/volksbanker/volksbank_line_item.rb
45
45
  - test/cli_test.rb
46
+ - test/fixtures/newlines.csv
46
47
  - test/fixtures/result.csv
47
48
  - test/fixtures/transactions-with-non-euro.csv
48
49
  - test/fixtures/transactions.csv
@@ -62,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
63
  version: '0'
63
64
  segments:
64
65
  - 0
65
- hash: 390847453253936748
66
+ hash: -982126049656369425
66
67
  required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  none: false
68
69
  requirements:
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  version: '0'
72
73
  segments:
73
74
  - 0
74
- hash: 390847453253936748
75
+ hash: -982126049656369425
75
76
  requirements: []
76
77
  rubyforge_project: volksbanker
77
78
  rubygems_version: 1.8.11
@@ -80,6 +81,7 @@ specification_version: 3
80
81
  summary: Prepares Volksbank's electronic statements for upload to Freeagent.
81
82
  test_files:
82
83
  - test/cli_test.rb
84
+ - test/fixtures/newlines.csv
83
85
  - test/fixtures/result.csv
84
86
  - test/fixtures/transactions-with-non-euro.csv
85
87
  - test/fixtures/transactions.csv