Last active
August 29, 2015 14:03
-
-
Save wteuber/b2760c6e337a7ebf3259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tokens = [/^:61/, /^:62F:/] | |
mt940 = <<MT940 | |
:20:951110 | |
:25:45050050/76198810 | |
:28:27/01 | |
:60F:C951016DEM84349,74 | |
:61:951017D6800,NCHK16703074 | |
:86:999PN5477SCHECK-NR. 0000016703074 | |
:61:951017D620,3NSTON | |
:86:999PN0911DAUERAUFTR.NR. 14 | |
:61:951017C18500,NCLRN | |
:86:999PN2406SCHECK | |
:61:951015D14220,NBOEN | |
:86:999PN0920WECHSEL | |
:61:951017D1507,NTRFN | |
:86:999PN0920SCHNELLUEB | |
:61:951024C4200,NMSCN | |
:86:999PN2506AUSSENH. NR. 1 | |
:61:951017D19900,NTRFN | |
:86:999PN0907UEBERTRAG | |
:61:951017D400,NTRFN | |
:86:999PN0891BTX | |
:61:951018C3656,74NMSCN | |
:86:999PN0850EINZAHLG.N | |
:61:951019C23040,NMSCN | |
:86:999PN0812LT.ANLAGE | |
:61:951027D5862,14NCHKN | |
:86:999PN5329AUSLSCHECK | |
:62F:C951017DEM84437,04 | |
MT940 | |
def next_str(str, tokens) | |
head = '' | |
body = '' | |
tail = str | |
tail.each_line do |line| | |
break if tokens.any?{ |token| token === line} | |
head << line | |
end | |
tail = tail[head.length..-1] | |
in_body = false | |
tail.each_line do |line| | |
if in_body | |
break if tokens.any?{ |token| token === line} | |
else | |
in_body = true | |
end | |
body << line | |
end | |
tail = tail[body.length..-1] | |
[head, body, tail] | |
end | |
tail = mt940 | |
begin | |
head, body, tail = next_str tail, tokens | |
puts body | |
puts '-'*10 | |
end until tail == '' | |
=begin # OUTPUT | |
:61:951017D6800,NCHK16703074 | |
:86:999PN5477SCHECK-NR. 0000016703074 | |
---------- | |
:61:951017D620,3NSTON | |
:86:999PN0911DAUERAUFTR.NR. 14 | |
---------- | |
:61:951017C18500,NCLRN | |
:86:999PN2406SCHECK | |
---------- | |
:61:951015D14220,NBOEN | |
:86:999PN0920WECHSEL | |
---------- | |
:61:951017D1507,NTRFN | |
:86:999PN0920SCHNELLUEB | |
---------- | |
:61:951024C4200,NMSCN | |
:86:999PN2506AUSSENH. NR. 1 | |
---------- | |
:61:951017D19900,NTRFN | |
:86:999PN0907UEBERTRAG | |
---------- | |
:61:951017D400,NTRFN | |
:86:999PN0891BTX | |
---------- | |
:61:951018C3656,74NMSCN | |
:86:999PN0850EINZAHLG.N | |
---------- | |
:61:951019C23040,NMSCN | |
:86:999PN0812LT.ANLAGE | |
---------- | |
:61:951027D5862,14NCHKN | |
:86:999PN5329AUSLSCHECK | |
---------- | |
:62F:C951017DEM84437,04 | |
---------- | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment