anz_bank_csv_cleaner 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/anz_bank_csv_cleaner.rb +89 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c47469bac26468defb821bc4bef7bc89b827fb7
|
4
|
+
data.tar.gz: 50d6314e3540c9c39bcf0c1b74474099284d7bec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a005fbc3d7409987b5795b1825698b802aacd176f7aeea6a3b105892cf66bb44a8004c8163f7ea5dba10783806ded519b242c40925eef085e0db88a00214e92b
|
7
|
+
data.tar.gz: 6801ac1cbcd7375e8c92ac579bdb1cc6e02f63f5756478657bb6eb4d1edbe9197f884d26824f4eeca6ea7cbefe522d3ddae2fd6bce2cdd0213b0db9b1295c8d4
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'CSV'
|
2
|
+
|
3
|
+
class ANZBankCSVCleaner
|
4
|
+
TYPE_FIELD = "Type"
|
5
|
+
DETAILS_FIELD = "Details"
|
6
|
+
PARTICULARS_FIELD = "Particulars"
|
7
|
+
CODE_FIELD = "Code"
|
8
|
+
REFERENCE_FIELD = "Reference"
|
9
|
+
AMOUNT_FIELD = "Amount"
|
10
|
+
DATE_FIELD = "Date"
|
11
|
+
DEBIT_VALUE = "DR"
|
12
|
+
CREDIT_VALUE = "CR"
|
13
|
+
VISA_PURCHASE_TYPE = "Visa Purchase"
|
14
|
+
EFTPOS_PURCHASE_TYPE = "Eft-Pos"
|
15
|
+
|
16
|
+
CLEAN_HEADER = [DATE_FIELD, AMOUNT_FIELD, TYPE_FIELD, DETAILS_FIELD]
|
17
|
+
|
18
|
+
def initialize(import_path:, export_path:)
|
19
|
+
@import_path = import_path
|
20
|
+
@export_path = export_path
|
21
|
+
|
22
|
+
unless (File.file?(@import_path))
|
23
|
+
raise StandardError.new("No input file")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
CSV.open(@export_path, "w", :write_headers => true, :headers => CLEAN_HEADER) do |clean_csv|
|
29
|
+
CSV.foreach(@import_path, :headers => true) do |import_row|
|
30
|
+
clean_csv << build_clean_row(import_row)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_required_fields(import_row)
|
38
|
+
if !import_row[DATE_FIELD]
|
39
|
+
raise StandardError.new("A '#{DATE_FIELD}' field is required.")
|
40
|
+
elsif !import_row[AMOUNT_FIELD]
|
41
|
+
raise StandardError.new("A '#{AMOUNT_FIELD}' field is required.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def use_field(field_value)
|
46
|
+
field_value && field_value.length > 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def clean_detail_field(import_row)
|
50
|
+
details_fields = []
|
51
|
+
type = import_row[TYPE_FIELD]
|
52
|
+
|
53
|
+
if(use_field(import_row[DETAILS_FIELD]) && type != VISA_PURCHASE_TYPE)
|
54
|
+
details_fields.push(import_row[DETAILS_FIELD])
|
55
|
+
end
|
56
|
+
|
57
|
+
if(use_field(import_row[PARTICULARS_FIELD]) && type != VISA_PURCHASE_TYPE && type != EFTPOS_PURCHASE_TYPE)
|
58
|
+
details_fields.push(import_row[PARTICULARS_FIELD])
|
59
|
+
end
|
60
|
+
|
61
|
+
if(use_field(import_row[CODE_FIELD]) && type != EFTPOS_PURCHASE_TYPE)
|
62
|
+
details_fields.push(import_row[CODE_FIELD])
|
63
|
+
end
|
64
|
+
|
65
|
+
if(use_field(import_row[REFERENCE_FIELD]) && type != VISA_PURCHASE_TYPE && type != EFTPOS_PURCHASE_TYPE)
|
66
|
+
details_fields.push(import_row[REFERENCE_FIELD])
|
67
|
+
end
|
68
|
+
|
69
|
+
details_field_result = ""
|
70
|
+
details_fields.each do |detail_field|
|
71
|
+
details_field_result << "#{detail_field} "
|
72
|
+
end
|
73
|
+
|
74
|
+
details_field_result
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_clean_row(import_row)
|
78
|
+
check_required_fields(import_row)
|
79
|
+
|
80
|
+
clean_row = []
|
81
|
+
amount = import_row[AMOUNT_FIELD].to_f
|
82
|
+
clean_row[0] = import_row[DATE_FIELD]
|
83
|
+
clean_row[1] = amount
|
84
|
+
clean_row[2] = amount > 0 ? CREDIT_VALUE : DEBIT_VALUE
|
85
|
+
clean_row[3] = clean_detail_field(import_row)
|
86
|
+
|
87
|
+
clean_row
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anz_bank_csv_cleaner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jordan Crawford
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ANZ Bank's CSV export contains many fields, making it difficult to identify
|
14
|
+
transactions. This Gem simplifies these fields, making the file easier to use.
|
15
|
+
email: jordan@crawford.kiwi
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/anz_bank_csv_cleaner.rb
|
21
|
+
homepage:
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Produces a cleaner version of the ANZ Bank CSV export for easier transaction
|
44
|
+
identification.
|
45
|
+
test_files: []
|