commerzbank-csv4gnucash 0.1.0 → 0.2.0
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 +4 -4
- data/commerzbank-csv4gnucash.gemspec +1 -1
- data/lib/commerzbank/csv4gnucash/version.rb +1 -1
- data/lib/commerzbank/csv4gnucash.rb +56 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c33752160b447765acf716fba8968d5bc9f9ae6b
|
4
|
+
data.tar.gz: 4a3f9da9a0a39b362aac4ac6416364dbea628d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b74948bcb21a1b86647599f87a8cec2160b05a41d1d2441b2f414df81ed461c7651e4a5eeb48bc934f3acccd87cbeafea29994eba863736c151cafa26b2eee7e
|
7
|
+
data.tar.gz: a6479f957152b6cff8f6f8d6304b346d9d9c4548c89f3702b208d18f2dd6fcb1e6c27710e0d96a811024a9e72c655d9d1c208e83ae8e2588326d729ab1094556
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
17
|
# delete this section to allow pushing this gem to any host.
|
18
18
|
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['allowed_push_host'] =
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
20
|
else
|
21
21
|
raise 'RubyGems 2.0 or newer is required to protect against' \
|
22
22
|
' public gem pushes.'
|
@@ -1,20 +1,67 @@
|
|
1
1
|
require 'commerzbank/csv4gnucash/version'
|
2
2
|
require 'csv'
|
3
|
+
require 'date'
|
3
4
|
require 'pp'
|
4
5
|
|
6
|
+
CSV::Converters[:foo] =
|
7
|
+
lambda do |f|
|
8
|
+
if f =~ /^\d{1,2}\.\d{1,2}\.\d{4}$/
|
9
|
+
Date.new(*f.split('.').map(&:to_i).reverse)
|
10
|
+
else
|
11
|
+
f
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
CSV::Converters[:bar] =
|
16
|
+
lambda do |f|
|
17
|
+
if f =~ /^-?[\d,.]+$/
|
18
|
+
# TODO: avoid floats
|
19
|
+
f.tr(',', '.').to_f
|
20
|
+
else
|
21
|
+
f
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Change Date format
|
26
|
+
class Date
|
27
|
+
def to_s
|
28
|
+
strftime('%Y%m%d')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Change Float format
|
33
|
+
class Float
|
34
|
+
def to_s
|
35
|
+
format('%.2f', self)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
5
39
|
module Commerzbank
|
6
40
|
# Csv4gnucash adopts Commerzbank CSV for GnuCash
|
7
41
|
module Csv4gnucash
|
8
|
-
def self.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
42
|
+
def self.convert(row)
|
43
|
+
conv = []
|
44
|
+
conv << row[:buchungstag]
|
45
|
+
conv << nil
|
46
|
+
conv << format('%s [%s]', row[:buchungstext], row[:umsatzart])
|
47
|
+
conv << nil
|
48
|
+
conv << 'Commerzbank'
|
49
|
+
conv << row[:betrag]
|
50
|
+
conv << nil
|
51
|
+
conv << nil
|
52
|
+
conv
|
53
|
+
end
|
54
|
+
|
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|
|
63
|
+
out << convert(row)
|
15
64
|
end
|
16
|
-
rescue EOFError => e
|
17
|
-
puts e
|
18
65
|
end
|
19
66
|
end
|
20
67
|
end
|