cremul-parser 0.0.2 → 0.0.3
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +20 -1
- data/lib/cremul/version.rb +1 -1
- data/lib/cremul_parser.rb +5 -3
- data/test/unit/parser_test.rb +13 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b691914d35e6f9391c1a478fe7692cb5342431f6
|
4
|
+
data.tar.gz: 977b5544bb1cd9155969dc1f5cef13553e725748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d72b563b87abd9829a2d8044ae2593026b6796b00c26047fb23a408f234b1248c5b7748fffaacbc8593f0653a3639ffbb43085761c20af6a97305c5f5c6c1135
|
7
|
+
data.tar.gz: ef76cb8a58a08d099b1681f442b383505b409f7f553192600349bad509d8efbf393a783f4b88ed53d9a9a83171f541d3b4ab06c8b96f7a54a53bdf47a4d3e278
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -27,7 +27,26 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
```
|
31
|
+
require 'cremul_parser'
|
32
|
+
|
33
|
+
f = File.open(<CREMUL-file>)
|
34
|
+
parser = CremulParser.new
|
35
|
+
parser.parse(f)
|
36
|
+
f.close
|
37
|
+
|
38
|
+
# or if the file is not utf-8 encoded
|
39
|
+
|
40
|
+
f = File.open(<CREMUL-file>)
|
41
|
+
parser = CremulParser.new
|
42
|
+
parser.parse(f, <encoding>) # for instance 'ISO-8859-1'
|
43
|
+
f.close
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
See the `parser_test.rb` file for more details.
|
48
|
+
|
49
|
+
## Version
|
31
50
|
|
32
51
|
## Copyright
|
33
52
|
|
data/lib/cremul/version.rb
CHANGED
data/lib/cremul_parser.rb
CHANGED
@@ -11,11 +11,13 @@ class CremulParser
|
|
11
11
|
def initialize
|
12
12
|
end
|
13
13
|
|
14
|
-
def parse(file)
|
14
|
+
def parse(file, file_encoding='utf-8')
|
15
15
|
file_as_a_string = ''
|
16
16
|
file.each do |line|
|
17
|
-
|
18
|
-
|
17
|
+
unless file_encoding == 'utf-8'
|
18
|
+
line = line.encode('utf-8', file_encoding)
|
19
|
+
end
|
20
|
+
file_as_a_string += line.chomp # remove \n and \r from the end of the line
|
19
21
|
end
|
20
22
|
@segments = file_as_a_string.split("'")
|
21
23
|
@msg = CremulMessage.new(@segments)
|
data/test/unit/parser_test.rb
CHANGED
@@ -148,6 +148,19 @@ describe CremulParser do
|
|
148
148
|
|
149
149
|
end
|
150
150
|
|
151
|
+
it 'should convert a non-utf-8 file to utf-8 on the fly' do
|
152
|
+
@parser.parse(File.open('files/CREMUL0001.dat'), 'ISO-8859-1')
|
153
|
+
@parser.segments.must_be_instance_of Array
|
154
|
+
@parser.msg.must_be_instance_of CremulMessage
|
155
|
+
|
156
|
+
msg = @parser.msg
|
157
|
+
line = msg.lines[0]
|
158
|
+
tx = line.transactions[0]
|
159
|
+
tx.must_be_instance_of CremulPaymentTx
|
160
|
+
tx.free_text.must_equal 'Tømrer Morten Rognebær AS'
|
161
|
+
|
162
|
+
end
|
163
|
+
|
151
164
|
|
152
165
|
end
|
153
166
|
|
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.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- CHANGELOG.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|