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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae18cc336fd0709c1ec2464ca1100ed83bdd4e2c
4
- data.tar.gz: 7bffb741a795bc7dfde8fa9217db06242adf94b4
3
+ metadata.gz: b691914d35e6f9391c1a478fe7692cb5342431f6
4
+ data.tar.gz: 977b5544bb1cd9155969dc1f5cef13553e725748
5
5
  SHA512:
6
- metadata.gz: 19b34e250c41da027bff129374af71792dfbf04187727d6c2bf7e7507ee5afe99a97a2bdd94a813ebcab1742e64c3db1dd15f024de57dededafb419713f8accc
7
- data.tar.gz: 4b2b4d6edefb945e7f8136fb9e224d9d671fc7f4d1728afd5cc599e7bd173f5ae558025284bea799be4315b19fbb28c82d201853e235e97614e916bde5a107f3
6
+ metadata.gz: d72b563b87abd9829a2d8044ae2593026b6796b00c26047fb23a408f234b1248c5b7748fffaacbc8593f0653a3639ffbb43085761c20af6a97305c5f5c6c1135
7
+ data.tar.gz: ef76cb8a58a08d099b1681f442b383505b409f7f553192600349bad509d8efbf393a783f4b88ed53d9a9a83171f541d3b4ab06c8b96f7a54a53bdf47a4d3e278
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.0.3
4
+
5
+ Added support for converting files to UTF-8 format on the fly.
6
+
7
+ ## 0.0.2
8
+
9
+ Updated doc only.
10
+
11
+ ## 0.0.1
12
+
13
+ Initial version
data/README.md CHANGED
@@ -27,7 +27,26 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
- See the `parser_test.rb` file.
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
 
@@ -1,3 +1,3 @@
1
1
  module Cremul
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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
- line.encode(Encoding::UTF_8)
18
- file_as_a_string += line.chop
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)
@@ -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.2
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-03-28 00:00:00.000000000 Z
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