Class: BanklineCsvImportFile

Inherits:
Object
  • Object
show all
Defined in:
lib/bankline_csv_import_file.rb,
lib/bankline_csv_import_file/record.rb,
lib/bankline_csv_import_file/version.rb

Defined Under Namespace

Classes: Record

Constant Summary collapse

VERSION =
"0.3.1"

Instance Method Summary collapse

Constructor Details

#initializeBanklineCsvImportFile

Returns a new instance of BanklineCsvImportFile.



8
9
10
# File 'lib/bankline_csv_import_file.rb', line 8

def initialize
  @records = []
end

Instance Method Details

#add_domestic_payment(payer_sort_code:, payer_account_number:, amount:, beneficiary_sort_code:, beneficiary_account_number:, beneficiary_name:, beneficiary_reference:, payment_date:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bankline_csv_import_file.rb', line 12

def add_domestic_payment(payer_sort_code:, payer_account_number:, amount:, beneficiary_sort_code:, beneficiary_account_number:, beneficiary_name:, beneficiary_reference:, payment_date:)
  formatted_payment_date = payment_date.strftime("%d%m%Y")
   = ("#{payer_sort_code}#{}")

  record = Record.new

  # https://www.business.rbs.co.uk/content/dam/rbs_co_uk/Business_and_Content/PDFs/Bankline/Bankline-import-file-guide-CSV-RBS.pdf
  # Section 4.2, page 46.
  record["T001"] = "01"  # 01 = Standard domestic payment.
  record["T010"] = 
  record["T014"] = sprintf("%.2f", BigDecimal(amount))
  record["T016"] = formatted_payment_date
  record["T022"] = (beneficiary_sort_code)
  record["T028"] = ()
  record["T030"] = domestic_normalize_string(beneficiary_name, max_length: 35)
  record["T034"] = domestic_normalize_string(beneficiary_reference, max_length: 18)

  @records << record
end

#add_international_payment(payer_sort_code:, payer_account_number:, amount:, beneficiary_bic:, beneficiary_iban:, beneficiary_name:, beneficiary_address: nil, beneficiary_reference:, payment_date:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bankline_csv_import_file.rb', line 32

def add_international_payment(payer_sort_code:, payer_account_number:, amount:, beneficiary_bic:, beneficiary_iban:, beneficiary_name:, beneficiary_address: nil, beneficiary_reference:, payment_date:)
  formatted_payment_date = payment_date.strftime("%d%m%Y")
   = ("#{payer_sort_code}#{}")

  normalized_iban = normalize_iban(beneficiary_iban)
  normalized_bic = normalize_bic(beneficiary_bic)

  beneficiary_country = normalized_iban[0, 2]

  beneficiary_address_line_1, beneficiary_address_line_2, beneficiary_address_line_3 =
    international_normalize_multiline_string(beneficiary_address, max_lines: 3, max_length_per_line: 35)

  beneficiary_reference_line_1, beneficiary_reference_line_2, beneficiary_reference_line_3, beneficiary_reference_line_4 =
    international_normalize_multiline_string(beneficiary_reference, max_lines: 4, max_length_per_line: 35)

  record = Record.new

  # https://www.business.rbs.co.uk/content/dam/rbs_co_uk/Business_and_Content/PDFs/Bankline/Bankline-import-file-guide-CSV-RBS.pdf
  # Section 4.6, page 54.
  record["T001"] = "04"  # 04 = International payment.
  record["T007"] = beneficiary_country
  record["T008"] = "N"  # Normal priority.
  record["T010"] = 
  record["T013"] = "GBP"  # Payment currency. (Presumably the target currency.)
  record["T014"] = sprintf("%.2f", BigDecimal(amount))
  record["T015"] = formatted_payment_date
  record["T022"] = normalized_bic
  record["T028"] = normalized_iban
  record["T030"] = international_normalize_string(beneficiary_name, max_length: 35)

  record["T031"] = beneficiary_address_line_1 if beneficiary_address_line_1
  record["T032"] = beneficiary_address_line_2 if beneficiary_address_line_2
  record["T033"] = beneficiary_address_line_3 if beneficiary_address_line_3

  record["T037"] = beneficiary_reference_line_1 if beneficiary_reference_line_1
  record["T038"] = beneficiary_reference_line_2 if beneficiary_reference_line_2
  record["T039"] = beneficiary_reference_line_3 if beneficiary_reference_line_3
  record["T040"] = beneficiary_reference_line_4 if beneficiary_reference_line_4

  record["T042"] = "GBP"  # Credit currency. (Presumably the source currency.)

  @records << record
end

#generateObject



76
77
78
79
80
81
82
# File 'lib/bankline_csv_import_file.rb', line 76

def generate
  CSV.generate do |csv|
    @records.each do |record|
      csv << record.to_csv
    end
  end
end