banker-ofx 0.4.0

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.
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Account do
4
+ describe "accounts" do
5
+ let(:file) { "spec/fixtures/sample.ofx" }
6
+ let(:ofx) { OFX::Parser::Base.new(file) }
7
+ let(:parser) { ofx.parser }
8
+ let(:accounts) { parser.bank_accounts }
9
+
10
+ context 'multiple accounts' do
11
+ let(:file) { "spec/fixtures/many_debit_accounts.ofx" }
12
+
13
+ it { accounts.should be_an_instance_of(Array) }
14
+ it { accounts.size.should eql(3) }
15
+ end
16
+
17
+ context 'debit' do
18
+ subject { accounts.first }
19
+
20
+ context 'keys' do
21
+ it { subject.should respond_to(:bank_id) }
22
+ it { subject.should respond_to(:id) }
23
+ it { subject.should respond_to(:type) }
24
+ it { subject.should respond_to(:transactions) }
25
+ it { subject.should respond_to(:balance) }
26
+ it { subject.should respond_to(:currency) }
27
+ end
28
+
29
+ context 'values' do
30
+ it { subject.currency.should eql("BRL") }
31
+ it { subject.bank_id.should eql("0356") }
32
+ it { subject.id.should eql("03227113109") }
33
+ it { subject.type.should eql(:checking) }
34
+ it { subject.transactions.should be_an_instance_of(Array) }
35
+ it { subject.transactions.size.should eql(36) }
36
+ it { subject.balance.amount.should eql(598.44) }
37
+ it { subject.balance.amount_in_pennies.should eql(59844) }
38
+ it { subject.balance.posted_at.should eql(Time.parse("2009-11-01")) }
39
+ end
40
+ end
41
+
42
+ context 'credit' do
43
+ let(:file) { "spec/fixtures/v211.ofx" }
44
+ let(:accounts) { parser.credit_cards }
45
+ subject { accounts.first }
46
+
47
+ context 'keys' do
48
+ it { subject.should respond_to(:id) }
49
+ it { subject.should respond_to(:transactions) }
50
+ it { subject.should respond_to(:balance) }
51
+ it { subject.should respond_to(:currency) }
52
+ end
53
+
54
+ context 'values' do
55
+ it { subject.currency.should eql("USD") }
56
+ it { subject.id.should eql("123412341234") }
57
+ it { subject.transactions.should be_an_instance_of(Array) }
58
+ it { subject.transactions.size.should eql(2) }
59
+ it { subject.balance.amount.should eql(-562.0) }
60
+ it { subject.balance.amount_in_pennies.should eql(-56200) }
61
+ it { subject.balance.posted_at.should eql(Time.parse("2005-08-31 16:51:53 +0100")) }
62
+ end
63
+ end
64
+
65
+
66
+ end
67
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Parser::OFX102 do
4
+ let(:file) { "spec/fixtures/sample.ofx" }
5
+ let(:ofx) { OFX::Parser::Base.new(file) }
6
+ let(:parser) { ofx.parser }
7
+ let(:accounts) { parser.bank_accounts }
8
+ let(:account) { accounts.first }
9
+
10
+ it "have a version" do
11
+ OFX::Parser::OFX102::VERSION.should eql("1.0.2")
12
+ end
13
+
14
+ it "set headers" do
15
+ parser.headers.should eql(ofx.headers)
16
+ end
17
+
18
+ it "trim trailing whitespace from headers" do
19
+ headers = OFX::Parser::OFX102.parse_headers("VERSION:102 ")
20
+ headers["VERSION"].should eql("102")
21
+ end
22
+
23
+ it "set body" do
24
+ parser.body.should eql(ofx.body)
25
+ end
26
+
27
+ it "set account" do
28
+ account.should be_an_instance_of(OFX::Account)
29
+ end
30
+
31
+ it "know about all transaction types" do
32
+ valid_types = [
33
+ 'CREDIT', 'DEBIT', 'INT', 'DIV', 'FEE', 'SRVCHG', 'DEP', 'ATM', 'POS', 'XFER',
34
+ 'CHECK', 'PAYMENT', 'CASH', 'DIRECTDEP', 'DIRECTDEBIT', 'REPEATPMT', 'OTHER'
35
+ ]
36
+
37
+ valid_types.sort.should eql(OFX::Parser::OFX102::TRANSACTION_TYPES.keys.sort)
38
+
39
+ valid_types.each do |transaction_type|
40
+ transaction_type.downcase.to_sym.should eql(OFX::Parser::OFX102::TRANSACTION_TYPES[transaction_type])
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Parser::OFX211 do
4
+ let(:file) { "spec/fixtures/v211.ofx" }
5
+ let(:ofx) { OFX::Parser::Base.new(file) }
6
+ let(:parser) { ofx.parser }
7
+ let(:accounts) { parser.bank_accounts }
8
+ let(:account) { accounts.first }
9
+
10
+ it "have a version" do
11
+ OFX::Parser::OFX211::VERSION.should eql("2.1.1")
12
+ end
13
+
14
+ it "set headers" do
15
+ parser.headers.should eql(ofx.headers)
16
+ end
17
+
18
+ it "set body" do
19
+ parser.body.should eql(ofx.body)
20
+ end
21
+
22
+ it "set account" do
23
+ account.should be_an_instance_of(OFX::Account)
24
+ end
25
+
26
+ context "transactions" do
27
+ let(:transactions) { account.transactions }
28
+
29
+ context "first" do
30
+ let(:transaction) { transactions[0] }
31
+
32
+ it "contain the correct values" do
33
+ transaction.amount.should eql(-80)
34
+ transaction.fit_id.should eql("219378")
35
+ transaction.memo.should be_empty
36
+ transaction.posted_at.should eql(Time.parse("2005-08-24 08:00:00"))
37
+ transaction.name.should eql("FrogKick Scuba Gear")
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,110 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Parser do
4
+ let(:file) { "spec/fixtures/sample.ofx" }
5
+ let(:ofx) { OFX::Parser::Base.new(file) }
6
+
7
+ it { ofx.should respond_to(:headers) }
8
+ it { ofx.should respond_to(:body) }
9
+ it { ofx.should respond_to(:content) }
10
+ it { ofx.should respond_to(:parser) }
11
+
12
+ context 'file path' do
13
+ it { ofx.content.should_not be_nil }
14
+ end
15
+
16
+ context 'file handler' do
17
+ let(:file) { open("spec/fixtures/sample.ofx") }
18
+
19
+ subject { ofx.content }
20
+
21
+ it { subject.should_not be_nil }
22
+ end
23
+
24
+ context 'file context' do
25
+ let(:file) { open("spec/fixtures/sample.ofx").read }
26
+
27
+ subject { ofx.content }
28
+
29
+ it { subject.should_not be_nil }
30
+ end
31
+
32
+ context 'content' do
33
+ subject { ofx.content }
34
+
35
+ it "set content" do
36
+ subject.should eql(open("spec/fixtures/sample.ofx").read)
37
+ end
38
+ end
39
+
40
+ context 'body' do
41
+ subject { ofx.body }
42
+
43
+ it "set body" do
44
+ subject.should_not be_nil
45
+ end
46
+ end
47
+
48
+ context 'encoding' do
49
+ let(:file) { "spec/fixtures/utf8.ofx" }
50
+
51
+ subject { ofx.content }
52
+
53
+ it "work with UTF8 and Latin1 encodings" do
54
+ subject.should eql(open("spec/fixtures/utf8.ofx", "r:iso-8859-1:utf-8").read)
55
+ end
56
+ end
57
+
58
+ context 'error handing' do
59
+ context 'invalid ofx' do
60
+ let(:file) { "spec/fixtures/invalid_version.ofx" }
61
+
62
+ it "raise exception when trying to parse an unsupported OFX version" do
63
+ lambda { ofx }.should raise_error(OFX::UnsupportedFileError)
64
+ end
65
+ end
66
+
67
+ context 'invalid file type' do
68
+ let(:file) { "spec/fixtures/avatar.gif" }
69
+
70
+ it "raise exception when trying to parse an unsupported OFX version" do
71
+ lambda { ofx }.should raise_error(OFX::UnsupportedFileError)
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "headers" do
77
+
78
+ subject { ofx.headers }
79
+
80
+ context 'should have' do
81
+ it { subject["OFXHEADER"].should eql("100") }
82
+ it { subject["DATA"].should eql("OFXSGML") }
83
+ it { subject["VERSION"].should eql("102") }
84
+ it { subject.should have_key("SECURITY") }
85
+ it { subject["SECURITY"].should be_nil }
86
+ it { subject["ENCODING"].should eql("USASCII") }
87
+ it { subject["CHARSET"].should eql("1252") }
88
+ it { subject.should have_key("COMPRESSION") }
89
+ it { subject["COMPRESSION"].should be_nil }
90
+ it { subject.should have_key("OLDFILEUID") }
91
+ it { subject["OLDFILEUID"].should be_nil }
92
+ it { subject.should have_key("NEWFILEUID") }
93
+ it { subject["NEWFILEUID"].should be_nil }
94
+ end
95
+
96
+ context 'CR LF Headers' do
97
+ let(:file) { ofx_with_carriage_return }
98
+
99
+ it "should parse headers with CR and without LF" do
100
+ subject.size.should eql(9)
101
+ end
102
+
103
+ def ofx_with_carriage_return
104
+ header = %{OFXHEADER:100\rDATA:OFXSGML\rVERSION:102\rSECURITY:NONE\rENCODING:USASCII\rCHARSET:1252\rCOMPRESSION:NONE\rOLDFILEUID:NONE\rNEWFILEUID:NONE\r}
105
+ body = open("spec/fixtures/sample.ofx").read.split(/<OFX>/, 2)[1]
106
+ header + "<OFX>" + body
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX do
4
+ describe "#OFX" do
5
+ it "should yield an OFX instance" do
6
+ OFX("spec/fixtures/sample.ofx") do |ofx|
7
+ ofx.class.should == OFX::Parser::OFX102
8
+ end
9
+ end
10
+
11
+ it "should be an OFX instance" do
12
+ OFX("spec/fixtures/sample.ofx") do
13
+ self.class.should == OFX::Parser::OFX102
14
+ end
15
+ end
16
+
17
+ it "should return parser" do
18
+ OFX("spec/fixtures/sample.ofx").class.should == OFX::Parser::OFX102
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,137 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Transaction do
4
+ let(:file) { "spec/fixtures/sample.ofx" }
5
+ let(:ofx) { OFX::Parser::Base.new(file) }
6
+ let(:parser) { ofx.parser }
7
+ let(:accounts) { parser.bank_accounts }
8
+ let(:account) { accounts.first }
9
+
10
+ context "debit" do
11
+ let(:transaction) { account.transactions[0] }
12
+
13
+ it "set amount" do
14
+ transaction.amount.should eql(-35.34)
15
+ end
16
+
17
+ it "cast amount to BigDecimal" do
18
+ transaction.amount.class.should eql(BigDecimal)
19
+ end
20
+
21
+ it "set amount in pennies" do
22
+ transaction.amount_in_pennies.should eql(-3534)
23
+ end
24
+
25
+ it "set fit id" do
26
+ transaction.fit_id.should eql("200910091")
27
+ end
28
+
29
+ it "set memo" do
30
+ transaction.memo.should eql("COMPRA VISA ELECTRON")
31
+ end
32
+
33
+ it "set check number" do
34
+ transaction.check_number.should eql("0001223")
35
+ end
36
+
37
+ it "have date" do
38
+ transaction.posted_at.should eql(Time.parse("2009-10-09 08:00:00"))
39
+ end
40
+
41
+ it "have type" do
42
+ transaction.type.should eql(:debit)
43
+ end
44
+ end
45
+
46
+ context "credit" do
47
+ let(:transaction) { account.transactions[1] }
48
+
49
+ it "set amount" do
50
+ transaction.amount.should eql(60.39)
51
+ end
52
+
53
+ it "set amount in pennies" do
54
+ transaction.amount_in_pennies.should eql(6039)
55
+ end
56
+
57
+ it "set fit id" do
58
+ transaction.fit_id.should eql("200910162")
59
+ end
60
+
61
+ it "set memo" do
62
+ transaction.memo.should eql("DEPOSITO POUP.CORRENTE")
63
+ end
64
+
65
+ it "set check number" do
66
+ transaction.check_number.should eql("0880136")
67
+ end
68
+
69
+ it "have date" do
70
+ transaction.posted_at.should eql(Time.parse("2009-10-16 08:00:00"))
71
+ end
72
+
73
+ it "have type" do
74
+ transaction.type.should eql(:credit)
75
+ end
76
+ end
77
+
78
+ context "with more info" do
79
+ let(:transaction) { account.transactions[2] }
80
+
81
+ it "set payee" do
82
+ transaction.payee.should eql("Pagto conta telefone")
83
+ end
84
+
85
+ it "set check number" do
86
+ transaction.check_number.should eql("000000101901")
87
+ end
88
+
89
+ it "have date" do
90
+ transaction.posted_at.should eql(Time.parse("2009-10-19 12:00:00"))
91
+ end
92
+
93
+ it "have type" do
94
+ transaction.type.should eql(:other)
95
+ end
96
+
97
+ it "have reference number" do
98
+ transaction.ref_number.should eql("101.901")
99
+ end
100
+ end
101
+
102
+ context "with name" do
103
+ let(:transaction) { account.transactions[3] }
104
+
105
+ it "set name" do
106
+ transaction.name.should eql("Pagto conta telefone")
107
+ end
108
+ end
109
+
110
+ context "with other types" do
111
+ let(:file) { "spec/fixtures/bb.ofx" }
112
+
113
+ context 'dep' do
114
+ let(:transaction) { account.transactions[9] }
115
+
116
+ it { transaction.type.should eql(:dep) }
117
+ end
118
+
119
+ context 'xfer' do
120
+ let(:transaction) { account.transactions[18] }
121
+
122
+ it { transaction.type.should eql(:xfer) }
123
+ end
124
+
125
+ context 'cash' do
126
+ let(:transaction) { account.transactions[45] }
127
+
128
+ it { transaction.type.should eql(:cash) }
129
+ end
130
+
131
+ context 'check' do
132
+ let(:transaction) { account.transactions[0] }
133
+
134
+ it { transaction.type.should eql(:check) }
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,25 @@
1
+ unless ENV['TRAVIS']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/spec'
5
+ end
6
+ end
7
+
8
+ require 'rspec'
9
+ require "ofx"
10
+
11
+ RSpec.configure do |config|
12
+ config.order = :rand
13
+ config.color_enabled = true
14
+
15
+ config.filter_run :focus => true
16
+ config.run_all_when_everything_filtered = true
17
+ end
18
+
19
+ RSpec::Matchers.define :have_key do |key|
20
+ match do |hash|
21
+ hash.respond_to?(:keys) &&
22
+ hash.keys.kind_of?(Array) &&
23
+ hash.keys.include?(key)
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banker-ofx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kyle Welsby
9
+ - Chuck Hardy
10
+ - Nando Vieira
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-05-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nokogiri
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: gem-release
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: simplecov
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ description: A simple OFX (Open Financial Exchange) parser built on top of Nokogiri.
81
+ Currently supports OFX 102, 200 and 211.
82
+ email:
83
+ - app@britishruby.com
84
+ - fnando.vieira@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rspec
91
+ - .rvmrc
92
+ - .travis.yml
93
+ - Gemfile
94
+ - Guardfile
95
+ - README.md
96
+ - Rakefile
97
+ - lib/ofx.rb
98
+ - lib/ofx/account.rb
99
+ - lib/ofx/balance.rb
100
+ - lib/ofx/errors.rb
101
+ - lib/ofx/foundation.rb
102
+ - lib/ofx/parser.rb
103
+ - lib/ofx/parser/ofx102.rb
104
+ - lib/ofx/parser/ofx211.rb
105
+ - lib/ofx/transaction.rb
106
+ - lib/ofx/version.rb
107
+ - ofx.gemspec
108
+ - spec/fixtures/avatar.gif
109
+ - spec/fixtures/bb.ofx
110
+ - spec/fixtures/invalid_version.ofx
111
+ - spec/fixtures/many_debit_accounts.ofx
112
+ - spec/fixtures/sample.ofx
113
+ - spec/fixtures/utf8.ofx
114
+ - spec/fixtures/v211.ofx
115
+ - spec/ofx/account_spec.rb
116
+ - spec/ofx/ofx102_spec.rb
117
+ - spec/ofx/ofx211_spec.rb
118
+ - spec/ofx/ofx_parser_spec.rb
119
+ - spec/ofx/ofx_spec.rb
120
+ - spec/ofx/transaction_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: https://github.com/BritRuby/Banker-OFX
123
+ licenses: []
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.21
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: A simple OFX (Open Financial Exchange) parser built on top of Nokogiri. Currently
146
+ supports OFX 102, 200 and 211.
147
+ test_files:
148
+ - spec/fixtures/avatar.gif
149
+ - spec/fixtures/bb.ofx
150
+ - spec/fixtures/invalid_version.ofx
151
+ - spec/fixtures/many_debit_accounts.ofx
152
+ - spec/fixtures/sample.ofx
153
+ - spec/fixtures/utf8.ofx
154
+ - spec/fixtures/v211.ofx
155
+ - spec/ofx/account_spec.rb
156
+ - spec/ofx/ofx102_spec.rb
157
+ - spec/ofx/ofx211_spec.rb
158
+ - spec/ofx/ofx_parser_spec.rb
159
+ - spec/ofx/ofx_spec.rb
160
+ - spec/ofx/transaction_spec.rb
161
+ - spec/spec_helper.rb