cremul-parser 0.0.5 → 0.0.6

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: f7d37e7ea9a0f2a71f205a8626cd1a3e3b40e0c2
4
- data.tar.gz: 223f59f9bad82d84c45707f52bcba71e467d3664
3
+ metadata.gz: f2c04ee6768afa1d21f139da326fb010b854930b
4
+ data.tar.gz: 9db6a55b1157b60a5c1152f1c160094480d752a3
5
5
  SHA512:
6
- metadata.gz: 559c0548efc556273b498b5501ebe69892ae6e664d1cce8cd617e254de65482b426d91760b703306029a2a25db34fa9437d2d6517969d1daf5d28742979e6a95
7
- data.tar.gz: 9576276c7c842514c3988dc92c909d948aab3ac00f93137059e34725236ff415a5b7d7b1087bcb5516b6335c355278bf35fb2a035e538615ab46cc5c922571fc
6
+ metadata.gz: bfc36832e27bd0ea30bf86f89a31dff2aeddbc107153a7ab24b883c2bb99e43fbc34930b8c2fc72c324c34e3751655ac798ade2b304d1d970449941ab84537c9
7
+ data.tar.gz: 2c0365b3dab99454e5ec557d71d7c2a1e3bcf865935abb689e04b24feaa415c179aaad66231f481807d7b8e5b070380695847c37a45e71e6416698bb522d4c19
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.6
4
+
5
+ - Corrected a bug in CremulPaymentTx so that it is now able to handle empty FII segments.
6
+ - Corrected a bug in CremulNameAndAddress so that it is now also able to handle addresses in structured form.
7
+
3
8
  ## 0.0.5
4
9
 
5
10
  - Refactored the ParserHelper to make it more DRY, and fixed a bug in CremulHeader regarding the parsing the
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # cremul-parser gem
2
2
 
3
3
  This is a simple parser for CREMUL payment transaction files written in Ruby. It parses
4
- the CREMUL file (which should be in UTF-8 encoding) and creates a Ruby object structure
5
- corresponding to the elements in the file.
4
+ the CREMUL file and creates a Ruby object structure corresponding to the elements in the file.
5
+
6
+ The parser is currently not a complete parser for all kinds of CREMUl files, but is
7
+ being developed further as needed in an ongoing project for a Norwegian customer.
6
8
 
7
9
  ## References
8
10
 
@@ -3,7 +3,20 @@ require_relative 'parser_helper'
3
3
  class CremulNameAndAddress
4
4
  include Cremul::ParserHelper
5
5
 
6
+ # NAD segment in unstructured form:
6
7
  # NAD+party-id+code+code+nad-line1+nad-line2+nad-line3+nad-line4+nad-line5
8
+ #
9
+ # NAD segment in structured form (3 variants):
10
+ # NAD+party-id+code+code+nad-line OR
11
+ # NAD+party-id+code+nad-line OR
12
+ # NAD+party-id+nad-line
13
+ #
14
+ # In the structured form the nad-line will have colon (:) as separator between the address parts
15
+ #
16
+ # Party-IDs:
17
+ # MR - Beneficiary bank
18
+ # BE - Beneficiary, the ultimate recipient of the funds
19
+ # PL - Payor
7
20
 
8
21
  attr_reader :type, :nad_lines
9
22
 
@@ -12,9 +25,15 @@ class CremulNameAndAddress
12
25
  @type = s[1].to_sym
13
26
 
14
27
  @nad_lines = []
15
- 5.times do |i|
16
- @nad_lines << s[i+4]
28
+ if s.size <= 5 # structured form
29
+ addr = s[s.size-1].split(':')
30
+ addr.size.times do |i|
31
+ @nad_lines << addr[i]
32
+ end
33
+ else
34
+ 5.times do |i|
35
+ @nad_lines << s[i+4]
36
+ end
17
37
  end
18
-
19
38
  end
20
39
  end
@@ -6,6 +6,16 @@ require_relative 'cremul_name_and_address'
6
6
  class CremulPaymentTx
7
7
  include Cremul::ParserHelper
8
8
 
9
+ # Normal format:
10
+ # FII+<party-id>+<account identification>
11
+ #
12
+ # Emtpy format (no bank account info given):
13
+ # FII+<party-id>
14
+ #
15
+ # Party-id:
16
+ # OR - Payor's bank account
17
+ # I2 - Beneficiary's bank account
18
+
9
19
  REF_TYPE_KID = 999 # Norwegian customer invoice reference
10
20
  REF_TYPE_INVOICE_NUMBER = 380
11
21
 
@@ -18,10 +28,12 @@ class CremulPaymentTx
18
28
  @posting_date = Date.parse(s[1])
19
29
 
20
30
  s = segments[next_fii_or_segment_index(segments, tx_segment_pos)].split('+')
21
- if s[2].include? ':'
22
- @payer_account_number = s[2].split(':')[0] # the part after the : is the payer account holder name
23
- else
24
- @payer_account_number = s[2]
31
+ if s.size == 3 # bank account number is provided
32
+ if s[2].include? ':'
33
+ @payer_account_number = s[2].split(':')[0] # the part after the : is the payer account holder name
34
+ else
35
+ @payer_account_number = s[2]
36
+ end
25
37
  end
26
38
 
27
39
  init_invoice_ref(segments, tx_segment_pos)
@@ -1,3 +1,3 @@
1
1
  module Cremul
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -0,0 +1,21 @@
1
+ UNA:+,? 'UNB+UNOC:3+00810506482+00975945065+140526:1430+01001500'UNH+1+CREMUL:D:
2
+ 96A:UN'BGM+455+1405261430'DTM+137:20140526:102'LIN+1'DTM+209:20140526:102'BUS++I
3
+ N'MOA+346:264:NOK'RFF+AII'FII+BF+12345678901'SEQ++1'DTM+193:20140526:102'DTM+209
4
+ :20140526:102'FII+OR'RFF+ACK:804574'MOA+60:264:NOK'MOA+98:314:NOK'CUX+2:NOK+3:NO
5
+ K+1'NAD+BE++RVO:REGIONALE VERNEOMBUD:OSLO'NAD+PL++BBR - BAUDIS BERGMANN ROESCH V
6
+ ERKEH:RSTECHNIK GMBH:PILLAUSTR. 1 E:38126 BRAUNSCHWEIG'FCA+14'MOA+23:50'PRC+11'
7
+ FTX+PMD+++KID 12121212121'LIN+2'DTM+209:20140526:102'BUS++IN'MOA+346:200:NOK'RFF
8
+ +AII'FII+BF+12345678901'SEQ++1'DTM+193:20140526:102'DTM+209:20140526:102'FII+OR'
9
+ RFF+ACK:812416'MOA+60:200:NOK'MOA+98:250:NOK'CUX+2:NOK+3:NOK+1'NAD+BE++RVO:BYGG
10
+ OG ANLEGG:PB 22 SENTRUM:0101 OSLO'NAD+PL++COLT NORDIC APS:LYNGBY HOVEDGADE 10:28
11
+ 00 KGS.LYNGBY'FCA+14'MOA+23:50'PRC+11'FTX+PMD+++REG NR 127763'LIN+3'DTM+209:2014
12
+ 0526:102'BUS++IN'MOA+346:200:NOK'RFF+AII'FII+BF+12345678901'SEQ++1'DTM+193:20140
13
+ 526:102'DTM+209:20140526:102'FII+OR'RFF+ACK:824584'MOA+60:200:NOK'MOA+98:250:NOK
14
+ 'CUX+2:NOK+3:NOK+1'NAD+BE++REGIONALE VERNEOMBUD BYGG OG ANLEGG:PB 22 SENTRUM 010
15
+ 1 OSLO'NAD+PL++UAB SUNRISA:TAIKOS 24:KLAIPEDA 11111 LT'FCA+14'MOA+23:50'PRC+11'F
16
+ TX+PMD+++KUNDEIDENTIFIKASJON (KID) 121212121:39'LIN+4'DTM+209:20140526:102'BUS++
17
+ IN'MOA+346:316,21:NOK'RFF+AII'FII+BF+12345678901'SEQ++1'DTM+193:20140526:102'DTM
18
+ +209:20140526:102'FII+OR'RFF+ACK:987226'RFF+AGN:UF0J02ID2MGGU001'MOA+60:316,21:N
19
+ OK'MOA+98:316,21:NOK'CUX+2:NOK+3:NOK+1'NAD+BE++Fondet for Regionale Verneom:Post
20
+ boks 22 Sentrum:0101 OSLO'NAD+PL++MONT??ZE PREROV A.S.'FCA+14'PRC+11'FTX+PMD+++
21
+ 22914324MONTAZE PREROV'CNT+LIN:4'UNT+85+1'UNZ+1+01001500'
@@ -0,0 +1,7 @@
1
+ UNA:+,? 'UNB+UNOC:3+00810506482+00975945065+140526:1455+01001501'UNH+1+CREMUL:D:
2
+ 96A:UN'BGM+455+1405261455'DTM+137:20140526:102'LIN+1'DTM+209:20140526:102'BUS++D
3
+ O'MOA+60:314:NOK'RFF+AII'FII+BF+12345678901'SEQ++1'DTM+193:20140526:102'FII+OR+1
4
+ 2345678901'RFF+ACK:837175'RFF+AEK:00000000237'RFF+ACD:797630907'MOA+119:314'NAD+
5
+ BE++FOND.FOR REGIONALE VERNEOMBUD'NAD+PL++Ole Thomessen:St. Nikolas-Gat
6
+ e 7::1706 SARPSBORG'PRC+8'DOC+380'MOA+12:314'FTX+PMD+++rvo'GIS+37'CNT+LIN:1'UNT+
7
+ 25+1'UNZ+1+01001501'
@@ -162,6 +162,35 @@ describe CremulParser do
162
162
 
163
163
  end
164
164
 
165
+ it 'should parse name and address correctly' do
166
+ @parser.parse(File.open('files/CREMUL0002-27.05.14.DAT'), 'ISO-8859-1')
167
+ @parser.segments.must_be_instance_of Array
168
+ @parser.msg.must_be_instance_of CremulMessage
169
+
170
+ msg = @parser.msg
171
+
172
+ tx = msg.lines[0].transactions[0]
173
+ tx.must_be_instance_of CremulPaymentTx
174
+ tx_payer = tx.payer_nad
175
+ tx_payer.must_be_instance_of CremulNameAndAddress
176
+ tx_payer.type.must_equal :PL
177
+ tx_payer.nad_lines[0].must_equal 'Ole Thomessen'
178
+ tx_payer.nad_lines[1].must_equal 'St. Nikolas-Gate 7'
179
+ tx_payer.nad_lines[3].must_equal '1706 SARPSBORG'
180
+ end
181
+
182
+ it 'should be able to parse a file with empty FII elements' do
183
+ @parser.parse(File.open('files/CREMUL0001-27.05.14.DAT'), 'ISO-8859-1')
184
+ @parser.segments.must_be_instance_of Array
185
+ @parser.msg.must_be_instance_of CremulMessage
186
+
187
+ msg = @parser.msg
188
+ msg.header.must_be_instance_of CremulHeader
189
+ msg.header.msg_id.must_include 'CREMUL'
190
+ msg.lines[0].transactions[0].payer_account_number.must_be_nil
191
+ end
192
+
193
+
165
194
  # the following test is commented out as the corresponding cremul test file is not included in the Git repo
166
195
  =begin
167
196
  it 'should parse a long file with multiple payment transactions' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cremul-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Per Spilling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,9 +64,11 @@ files:
64
64
  - lib/cremul/version.rb
65
65
  - lib/cremul_parser.rb
66
66
  - test/test_helper.rb
67
+ - test/unit/files/CREMUL0001-27.05.14.DAT
67
68
  - test/unit/files/CREMUL0001-utf-8.txt
68
69
  - test/unit/files/CREMUL0001.DAT
69
70
  - test/unit/files/CREMUL0001_1.DAT
71
+ - test/unit/files/CREMUL0002-27.05.14.DAT
70
72
  - test/unit/files/CREMUL0002-utf-8.txt
71
73
  - test/unit/files/CREMUL0002.DAT
72
74
  - test/unit/files/CREMUL0003-utf-8.txt
@@ -101,9 +103,11 @@ specification_version: 4
101
103
  summary: A parser for CREMUL payment transaction files
102
104
  test_files:
103
105
  - test/test_helper.rb
106
+ - test/unit/files/CREMUL0001-27.05.14.DAT
104
107
  - test/unit/files/CREMUL0001-utf-8.txt
105
108
  - test/unit/files/CREMUL0001.DAT
106
109
  - test/unit/files/CREMUL0001_1.DAT
110
+ - test/unit/files/CREMUL0002-27.05.14.DAT
107
111
  - test/unit/files/CREMUL0002-utf-8.txt
108
112
  - test/unit/files/CREMUL0002.DAT
109
113
  - test/unit/files/CREMUL0003-utf-8.txt