Improve parsing of BankTransactionReference

Allow more characters before and after the actual reference.
Also use the correct matching method during testing.
This commit is contained in:
Patrick Gansterer 2021-02-08 03:39:47 +01:00
parent 88228022e3
commit ca0398632b
2 changed files with 51 additions and 15 deletions

View file

@ -2,7 +2,7 @@ class BankTransactionReference
# parses a string from a bank transaction field
def self.parse(data)
m = /(^|\s)FS(?<group>\d+)(\.(?<user>\d+))?(?<parts>([A-Za-z]+\d+(\.\d+)?)+)(\s|$)/.match(data)
m = /(^|[^\w\.])FS(?<group>\d+)(\.(?<user>\d+))?(?<parts>([A-Za-z]+\d+(\.\d+)?)+)([^\w\.]|$)/.match(data)
return unless m
parts = {}
@ -12,8 +12,8 @@ class BankTransactionReference
parts[category] = value
end
ret = { group: m[:group], parts: parts }
ret[:user] = m[:user] if m[:user]
ret = { group: m[:group].to_i, parts: parts }
ret[:user] = m[:user].to_i if m[:user]
return ret
end