You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-20Lines changed: 39 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,25 +38,11 @@ Or install it yourself as:
38
38
39
39
## Usage
40
40
41
-
Simple usage:
41
+
### Simple usage:
42
42
43
43
```ruby
44
+
statements =Cmxl.parse(File.read('mt940.txt'))
44
45
45
-
# Configuration:
46
-
47
-
# statement divider regex to split the individual statements in one file - the default is standard and should be good for most files
48
-
Cmxl.config[:statement_separator] =/\n-.\n/m
49
-
50
-
# do you want an error to be raised when a line can not be parsed? default is true
51
-
Cmxl.config[:raise_line_format_errors] =true
52
-
53
-
# try to stip the SWIFT header data. This strips everything until the actual first MT940 field. (if parsing fails, try this!)
54
-
Cmxl.config[:strip_headers] =true
55
-
56
-
57
-
# Statment parsing:
58
-
59
-
statements =Cmxl.parse(File.read('mt940.txt'), :encoding => 'ISO-8859-1') # parses the file and returns an array of statement objects. Please note: if no encoding is given Cmxl tries to guess the encoding from the content and converts it to UTF-8.
60
46
statements.each do |s|
61
47
puts s.reference
62
48
puts s.generation_date
@@ -81,25 +67,58 @@ statements.each do |s|
81
67
# ...
82
68
end
83
69
end
84
-
85
70
```
86
71
87
72
Every object responds to `to_h` and let's you easily convert the data to a hash. Also every object responds to `to_json` which lets you easily represent the statements as JSON with your favorite JSON library.
88
73
89
-
#### A note about encoding and file weirdnesses
74
+
###File encoding options
90
75
91
76
You probably will encounter encoding issues (hey, you are building banking applications!).
92
77
We try to handle encoding and format weirdnesses as much as possible. If no encoding is passed we try to guess the encoding of the data and convert it to UTF8.
93
78
In the likely case that you encounter encoding issues you can pass encoding options to `Cmxl.parse(<string>, <options hash>)`. It accepts the same options as [String#encode](http://ruby-doc.org/core-2.1.3/String.html#method-i-encode)
94
79
If that fails, try to modify the file before you pass it to the parser - and please create an issue.
0 commit comments