railslove / cmxl

your friendly MT940 SWIFT file parser for bank statements
http://railslove.com
MIT License
46 stars 25 forks source link

Lines with non-digit tags should be parsed too. #23

Closed prometh07 closed 5 years ago

prometh07 commented 5 years ago

Scenario: I'm trying to parse a file with a header containing a line with a custom, non-digit tag, eg. :NS:some-description.

Available options:

  1. Ignore errors by setting Cmxl.config[:raise_line_format_errors] = false
  2. Strip headers.

None of these is helpful. However, I think there are some solutions to the problem:

  1. Change regex used to match tags in self.parse(line) inside field.rb
  2. Allow to ignore lines starting with certain tags or meeting another critiera.

I can make a PR, if you want so.

bumi commented 5 years ago

ahh interesting. do you have an example of such a file? I've never seen something like that so far. What is the spec/content of those? if they follow some standard maybe we can add proper parsing of those?

PRs are generally welcome!

prometh07 commented 5 years ago

Take a look at https://github.com/WoLpH/mt940/commit/e4d36fe165bd1059c7fa2d5dbeeaa58fa41fa394 and ftp://ftp.kamsoft.pl/pub/KS-FKW/Pomoce/MT940/PekaoBIZNES24_MC.pdf or https://github.com/WoLpH/mt940/issues/23

Here's an example from the last link:

:20:STARTUMS
:25:1222333444
:28:1/1
:NS:22Test GmbH
23Testkonto
240,800
25010102311202
3037010000
...
bumi commented 5 years ago

ok, interesting... "non-swift" .

I think we should add proper support for that then.

It should be possible to simply add a new parser as described here). And adjust the regex here to support non decimal tags.

A PR would be great! I'm happy to help if you have questions.

prometh07 commented 5 years ago

Well, so I made a tiny commit. But don't you think it would beneficial to emphasize the fact that newly defined custom field parsers are automatically added to Field.parsers hash (ie. they are used when parsing a file)? Because right now it's not entirely clear or convincing.

bumi commented 5 years ago

thanks, will look at it asap. regarding your comment: you mean that should me mentioned clearly in the readme? Just looked at the readme and you're right it is not clear that it will automatically used. -> ruby magic :)

Uepsilon commented 5 years ago

fixed by merging #26, thanks @prometh07 👍