cmxl 0.0.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,7 +21,6 @@ Cmxl is a pure ruby parser and has no gem dependencies.
21
21
 
22
22
  ## Installation
23
23
 
24
-
25
24
  Add this line to your application's Gemfile:
26
25
 
27
26
  gem 'cmxl'
@@ -40,7 +39,16 @@ Simple usage:
40
39
 
41
40
  ```ruby
42
41
 
43
- statements = Cmxl.parse(File.read('mt940.txt')) # parses the file and returns an array of statement objects
42
+ # Configuration:
43
+ # Cmxl currently allows you to configure the statement divider - though the default should be good in most of the cases
44
+ # and you can configure if line parsing errors should be raised
45
+
46
+ Cmxl.config[:statement_separator] = /\n-.\n/m
47
+ Cmxl.config[:raise_line_format_errors] = true
48
+
49
+ # Statment parsing:
50
+
51
+ statements = Cmxl.parse(File.read('mt940.txt'), :encoding => 'ISO-8859-1') # parses the file and returns an array of statement objects
44
52
  statements.each do |s|
45
53
  puts s.reference
46
54
  puts s.generation_date
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec", '~>3.0'
26
+
27
+ spec.add_dependency "rchardet19"
26
28
  end
@@ -1,9 +1,12 @@
1
1
  require "cmxl/version"
2
2
 
3
+ require "rchardet19"
4
+
3
5
  require 'cmxl/field'
4
6
  require 'cmxl/statement'
5
7
  require 'cmxl/transaction'
6
8
  Dir[File.join(File.dirname(__FILE__), 'cmxl/fields', '*.rb')].each { |f| require f; }
9
+
7
10
  module Cmxl
8
11
  def self.config
9
12
  @config
@@ -24,6 +27,11 @@ module Cmxl
24
27
  # Returns an array of Statement objects
25
28
  def self.parse(data, options={})
26
29
  options[:universal_newline] ||= true
30
+ # if no encoding is provided we try to guess using CharDet
31
+ if options[:encoding].nil? && cd = CharDet.detect(data, silent: true)
32
+ options[:encoding] = cd.encoding
33
+ end
34
+
27
35
  if options[:encoding]
28
36
  data.encode!('UTF-8', options.delete(:encoding), options)
29
37
  else
@@ -1,3 +1,3 @@
1
1
  module Cmxl
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,16 @@
1
+ :20:1234567
2
+ :21:9876543210
3
+ :25:10020030/1234567
4
+ :28C:5/1
5
+ :60F:C021101EUR2187,95
6
+ :61:0211011102DR800,NSTONONREF//55555
7
+ :86:008?00DAUERAUFTRAG?100599?20Miete November?3010020030?31234567?32MUELLER?34339
8
+ :61:0211021102CR3000,NTRFNONREF//55555
9
+ :86:051?00�BERWEISUNG?100599?20Gehalt Oktob
10
+ er
11
+ ?21Firma
12
+ M�stermann
13
+ GmbH?3050060400?31084756
14
+ 4700?32M�LLER?34339
15
+ :62F:C021131EUR4387,95
16
+
@@ -1,6 +1,20 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'parsing a statement' do
6
+
7
+ context 'ISO 8859-1' do
8
+ subject { Cmxl.parse(mt940_file('mt940-iso8859-1'))[0] }
9
+ it { expect(subject.reference).to eql('1234567') }
10
+ it { expect(subject.opening_balance.amount_in_cents).to eql(218795) }
11
+ it { expect(subject.closing_balance.amount_in_cents).to eql(438795) }
12
+ it { expect(subject.transactions.last.description).to eql('ÜBERWEISUNG') }
13
+ it { expect(subject.transactions.last.information).to eql('Gehalt OktoberFirmaMüstermannGmbH') }
14
+ it { expect(subject.transactions.last.name).to eql('MÜLLER') }
15
+ it { expect(subject.transactions.last.bic).to eql('50060400') }
16
+ end
17
+
4
18
  context 'first example' do
5
19
  subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[0] }
6
20
  it { expect(subject.reference).to eql('131110') }
@@ -30,20 +44,22 @@ describe 'parsing a statement' do
30
44
  it { expect(subject.transactions.first.iban).to eql('234567') }
31
45
  end
32
46
 
33
- context 'third example' do
34
- subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[2] }
35
- it { expect(subject.reference).to eql('TELEWIZORY S.A.') }
36
- it { expect(subject.opening_balance.amount_in_cents).to eql(4000000) }
37
- it { expect(subject.closing_balance.amount_in_cents).to eql(5004000) }
38
- it { expect(subject.reference).to eql("TELEWIZORY S.A.") }
39
- it { expect(subject.transactions.count).to eql(3) }
40
- it { expect(subject.transactions.first.description).to eql('Wyplata-(dysp/przel)') }
41
- it { expect(subject.transactions.first.information).to eql('0810600076000077777777777715617INFO INFO INFO INFO INFO INFO 1 ENDINFO INFO INFO INFO INFOINFO 2 ENDZAPLATA ZA FABRYKATY DO TUB - 200 S ZTUK, TRANZYSTORY-300 SZT GR544 I OPORNIKI-500 SZT GTX847 FAKTURA 333/2003.') }
42
- it { expect(subject.transactions.first.name).to eql('HUTA SZKLA TOPIC ULPRZEMYSLOWA 67 32-669 WROCLAW') }
43
- it { expect(subject.transactions.first.bic).to eql('10600076') }
44
- it { expect(subject.transactions.first.iban).to eql('PL08106000760000777777777777') }
45
- it { expect(subject.transactions.first.sepa).to eql({}) }
46
- end
47
+
48
+
49
+ context 'third example' do
50
+ subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[2] }
51
+ it { expect(subject.reference).to eql('TELEWIZORY S.A.') }
52
+ it { expect(subject.opening_balance.amount_in_cents).to eql(4000000) }
53
+ it { expect(subject.closing_balance.amount_in_cents).to eql(5004000) }
54
+ it { expect(subject.reference).to eql("TELEWIZORY S.A.") }
55
+ it { expect(subject.transactions.count).to eql(3) }
56
+ it { expect(subject.transactions.first.description).to eql('Wyplata-(dysp/przel)') }
57
+ it { expect(subject.transactions.first.information).to eql('0810600076000077777777777715617INFO INFO INFO INFO INFO INFO 1 ENDINFO INFO INFO INFO INFOINFO 2 ENDZAPLATA ZA FABRYKATY DO TUB - 200 S ZTUK, TRANZYSTORY-300 SZT GR544 I OPORNIKI-500 SZT GTX847 FAKTURA 333/2003.') }
58
+ it { expect(subject.transactions.first.name).to eql('HUTA SZKLA TOPIC ULPRZEMYSLOWA 67 32-669 WROCLAW') }
59
+ it { expect(subject.transactions.first.bic).to eql('10600076') }
60
+ it { expect(subject.transactions.first.iban).to eql('PL08106000760000777777777777') }
61
+ it { expect(subject.transactions.first.sepa).to eql({}) }
62
+ end
47
63
 
48
64
 
49
65
  end
metadata CHANGED
@@ -1,57 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmxl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Michael Bumann
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
12
+ date: 2014-09-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '1.5'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.5'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '3.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rchardet19
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
55
78
  description: Cmxl provides an friendly, extensible and customizable parser for the
56
79
  MT940 bank statement format.
57
80
  email:
@@ -60,8 +83,8 @@ executables: []
60
83
  extensions: []
61
84
  extra_rdoc_files: []
62
85
  files:
63
- - ".gitignore"
64
- - ".travis.yml"
86
+ - .gitignore
87
+ - .travis.yml
65
88
  - Gemfile
66
89
  - LICENSE.txt
67
90
  - README.md
@@ -100,6 +123,7 @@ files:
100
123
  - spec/fixtures/lines/statement_details.txt
101
124
  - spec/fixtures/lines/statement_line.txt
102
125
  - spec/fixtures/lines/statement_number.txt
126
+ - spec/fixtures/mt940-iso8859-1.txt
103
127
  - spec/fixtures/mt940.txt
104
128
  - spec/mt940_parsing_spec.rb
105
129
  - spec/spec_helper.rb
@@ -108,28 +132,29 @@ files:
108
132
  homepage: https://github.com/railslove/cmxl
109
133
  licenses:
110
134
  - MIT
111
- metadata: {}
112
- post_install_message: "Thanks for using Cmxl - your friendly MT940 parser!\nWe hope
135
+ post_install_message: ! "Thanks for using Cmxl - your friendly MT940 parser!\nWe hope
113
136
  we can make dealing with MT940 files a bit more fun. :) \nPlease create an issue
114
137
  on github if anything is not as expected.\n\n"
115
138
  rdoc_options: []
116
139
  require_paths:
117
140
  - lib
118
141
  required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
119
143
  requirements:
120
- - - ">="
144
+ - - ! '>='
121
145
  - !ruby/object:Gem::Version
122
146
  version: '0'
123
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
124
149
  requirements:
125
- - - ">="
150
+ - - ! '>='
126
151
  - !ruby/object:Gem::Version
127
152
  version: '0'
128
153
  requirements: []
129
154
  rubyforge_project:
130
- rubygems_version: 2.2.2
155
+ rubygems_version: 1.8.23.2
131
156
  signing_key:
132
- specification_version: 4
157
+ specification_version: 3
133
158
  summary: Cmxl is your friendly MT940 bank statement parser
134
159
  test_files:
135
160
  - spec/field_spec.rb
@@ -152,9 +177,9 @@ test_files:
152
177
  - spec/fixtures/lines/statement_details.txt
153
178
  - spec/fixtures/lines/statement_line.txt
154
179
  - spec/fixtures/lines/statement_number.txt
180
+ - spec/fixtures/mt940-iso8859-1.txt
155
181
  - spec/fixtures/mt940.txt
156
182
  - spec/mt940_parsing_spec.rb
157
183
  - spec/spec_helper.rb
158
184
  - spec/support/fixtures.rb
159
185
  - spec/transaction_spec.rb
160
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 29c6b73c044ebe4baf36ef42a8740f0d92a8b186
4
- data.tar.gz: 2a69e78bdea382565fec283e23d90eb1809b5222
5
- SHA512:
6
- metadata.gz: 0054825050267f040b34236f2105b798b1aebcf68c51659ebc3396358c75f024e1a021368d9cc1679073a08d28e084e496a167b9443a61cb245d8a289c7e685e
7
- data.tar.gz: 2fc88b2861fdb09dc48975f538dc4856011194670b818379f93591824c46be8a6a6f1f7db42bebf411b84d4650fe2bf6872053819122eed6985049fb58ead83b