commerzbank-csv4gnucash 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c33752160b447765acf716fba8968d5bc9f9ae6b
4
- data.tar.gz: 4a3f9da9a0a39b362aac4ac6416364dbea628d35
3
+ metadata.gz: 121622f2b9586d8d198d5e24456df41f30b5c873
4
+ data.tar.gz: cb633bb9faf9ba14cf59fd1b7c2241cda9871b91
5
5
  SHA512:
6
- metadata.gz: b74948bcb21a1b86647599f87a8cec2160b05a41d1d2441b2f414df81ed461c7651e4a5eeb48bc934f3acccd87cbeafea29994eba863736c151cafa26b2eee7e
7
- data.tar.gz: a6479f957152b6cff8f6f8d6304b346d9d9c4548c89f3702b208d18f2dd6fcb1e6c27710e0d96a811024a9e72c655d9d1c208e83ae8e2588326d729ab1094556
6
+ metadata.gz: 52df28076554d21f1e940f9a0fb88cdeeff693ad2dd170fbc339fd6eae99f9e13e8d36a642c8a213901771d8823011fbaa078ae6bc2782ea9c855f210b34d1af
7
+ data.tar.gz: ab796a4a3b825640af3228346fe5907a967c5f483c4f9a71526a19690f8ac550e28457eae316e88a4a34c5774b5971e49d42100c91166044afe8b6bbfc0a1a09
@@ -3,6 +3,21 @@ require 'csv'
3
3
  require 'date'
4
4
  require 'pp'
5
5
 
6
+ # Wrap a given stream and normalize line endings.
7
+ # Works for LF and CRLF line endings.
8
+ class LineEndingNormalizer
9
+ def initialize(wrapped)
10
+ @wrapped = wrapped
11
+ end
12
+
13
+ def gets(arg)
14
+ raise "Expected #{"\n".inspect} but got #{arg.inspect}" unless arg == '\\n'
15
+ line = @wrapped.gets
16
+ line = line.chomp if line
17
+ line
18
+ end
19
+ end
20
+
6
21
  CSV::Converters[:foo] =
7
22
  lambda do |f|
8
23
  if f =~ /^\d{1,2}\.\d{1,2}\.\d{4}$/
@@ -16,7 +31,7 @@ CSV::Converters[:bar] =
16
31
  lambda do |f|
17
32
  if f =~ /^-?[\d,.]+$/
18
33
  # TODO: avoid floats
19
- f.tr(',', '.').to_f
34
+ f.tr('.', '').tr(',', '.').to_f
20
35
  else
21
36
  f
22
37
  end
@@ -39,6 +54,22 @@ end
39
54
  module Commerzbank
40
55
  # Csv4gnucash adopts Commerzbank CSV for GnuCash
41
56
  module Csv4gnucash
57
+ def self.with_csv_output(output)
58
+ CSV(output) { |csv| yield csv }
59
+ end
60
+
61
+ def self.with_csv_input(input)
62
+ CSV.new(LineEndingNormalizer.new(input),
63
+ col_sep: ';',
64
+ row_sep: '\n',
65
+ headers: true,
66
+ header_converters: :symbol,
67
+ converters: [:foo, :bar]
68
+ ).each do |row|
69
+ yield row
70
+ end
71
+ end
72
+
42
73
  def self.convert(row)
43
74
  conv = []
44
75
  conv << row[:buchungstag]
@@ -52,14 +83,9 @@ module Commerzbank
52
83
  conv
53
84
  end
54
85
 
55
- def self.main(_input)
56
- CSV($stdout) do |out|
57
- CSV.new(ARGF,
58
- col_sep: ';',
59
- headers: true,
60
- header_converters: :symbol,
61
- converters: [:foo, :bar]
62
- ).each do |row|
86
+ def self.main(input)
87
+ with_csv_output($stdout) do |out|
88
+ with_csv_input(input) do |row|
63
89
  out << convert(row)
64
90
  end
65
91
  end
@@ -1,5 +1,5 @@
1
1
  module Commerzbank
2
2
  module Csv4gnucash
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commerzbank-csv4gnucash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kilian Sprotte