Skip to content

Commit 67e11be

Browse files
Refact the parser logic to use OFX102 class when it is an OFX with version 103 (#10)
Co-authored-by: Marcos de Melo <[email protected]>
1 parent fceb4c1 commit 67e11be

File tree

7 files changed

+26
-158
lines changed

7 files changed

+26
-158
lines changed

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ GEM
3434
rb-inotify (~> 0.9, >= 0.9.10)
3535
lumberjack (1.2.10)
3636
method_source (1.1.0)
37-
mini_portile2 (2.8.7)
37+
mini_portile2 (2.8.9)
3838
nenv (0.3.0)
3939
nkf (0.2.0)
40-
nokogiri (1.14.5)
41-
mini_portile2 (~> 2.8.0)
40+
nokogiri (1.15.7)
41+
mini_portile2 (~> 2.8.2)
4242
racc (~> 1.4)
4343
notiffany (0.1.3)
4444
nenv (~> 0.1)

lib/ofx.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
require 'ofx/errors'
1010
require 'ofx/parser'
1111
require 'ofx/parser/ofx102'
12-
require 'ofx/parser/ofx103'
1312
require 'ofx/parser/ofx211'
1413
require 'ofx/foundation'
1514
require 'ofx/balance'

lib/ofx/parser.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ def initialize(resource)
1717
end
1818

1919
case headers["VERSION"]
20-
when /100|102/ then
20+
when /100|102|103/ then
2121
@parser = OFX102.new(:headers => headers, :body => body)
22-
when /103/ then
23-
@parser = OFX103.new(:headers => headers, :body => body)
2422
when /200|202|211|220/ then
2523
@parser = OFX211.new(:headers => headers, :body => body)
2624
else

lib/ofx/parser/ofx103.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

spec/fixtures/v103.ofx

Lines changed: 0 additions & 80 deletions
This file was deleted.

spec/ofx/ofx103_spec.rb

Lines changed: 0 additions & 51 deletions
This file was deleted.

spec/ofx/ofx_parser_spec.rb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
require "spec_helper"
22

33
describe OFX::Parser do
4+
def ofx_example_to(version)
5+
<<~OFX_CONTENT
6+
<?xml version="1.0" encoding="US-ASCII"?>
7+
8+
<?OFX OFXHEADER="200" VERSION="#{version}" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>"
9+
10+
<OFX>
11+
</OFX>
12+
OFX_CONTENT
13+
end
14+
415
before do
516
@ofx = OFX::Parser::Base.new("spec/fixtures/sample.ofx")
617
end
@@ -50,28 +61,35 @@
5061
it "uses 102 parser to parse version 100 ofx files" do
5162
expect(OFX::Parser::OFX102).to receive(:new).and_return('ofx-102-parser')
5263

53-
ofx = OFX::Parser::Base.new(ofx_2_example('100'))
64+
ofx = OFX::Parser::Base.new(ofx_example_to('100'))
65+
expect(ofx.parser).to eql 'ofx-102-parser'
66+
end
67+
68+
it "uses 102 parser to parse version 103 ofx files" do
69+
expect(OFX::Parser::OFX102).to receive(:new).and_return('ofx-102-parser')
70+
71+
ofx = OFX::Parser::Base.new(ofx_example_to('103'))
5472
expect(ofx.parser).to eql 'ofx-102-parser'
5573
end
5674

5775
it "uses 211 parser to parse version 200 ofx files" do
5876
expect(OFX::Parser::OFX211).to receive(:new).and_return('ofx-211-parser')
5977

60-
ofx = OFX::Parser::Base.new(ofx_2_example('200'))
78+
ofx = OFX::Parser::Base.new(ofx_example_to('200'))
6179
expect(ofx.parser).to eql 'ofx-211-parser'
6280
end
6381

6482
it "uses 211 parser to parse version 202 ofx files" do
6583
expect(OFX::Parser::OFX211).to receive(:new).and_return('ofx-211-parser')
6684

67-
ofx = OFX::Parser::Base.new(ofx_2_example('202'))
85+
ofx = OFX::Parser::Base.new(ofx_example_to('202'))
6886
expect(ofx.parser).to eql 'ofx-211-parser'
6987
end
7088

7189
it "uses 211 parser to parse version 220 ofx files" do
7290
expect(OFX::Parser::OFX211).to receive(:new).and_return('ofx-211-parser')
7391

74-
ofx = OFX::Parser::Base.new(ofx_2_example('220'))
92+
ofx = OFX::Parser::Base.new(ofx_example_to('220'))
7593
expect(ofx.parser).to eql 'ofx-211-parser'
7694
end
7795

@@ -125,13 +143,4 @@
125143
expect(@ofx.headers.size).to be(9)
126144
end
127145
end
128-
129-
def ofx_2_example(version)
130-
<<-EndOfx
131-
<?xml version="1.0" encoding="US-ASCII"?>
132-
<?OFX OFXHEADER="200" VERSION="#{version}" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>"
133-
<OFX>
134-
</OFX>
135-
EndOfx
136-
end
137146
end

0 commit comments

Comments
 (0)