ofx_br 0.3.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +13 -0
  3. data/.gitignore +4 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +9 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +50 -0
  8. data/README.rdoc +51 -0
  9. data/Rakefile +7 -0
  10. data/lib/ofx_br/account.rb +11 -0
  11. data/lib/ofx_br/balance.rb +7 -0
  12. data/lib/ofx_br/errors.rb +3 -0
  13. data/lib/ofx_br/foundation.rb +9 -0
  14. data/lib/ofx_br/parser/ofx102.rb +201 -0
  15. data/lib/ofx_br/parser/ofx103.rb +7 -0
  16. data/lib/ofx_br/parser/ofx211.rb +40 -0
  17. data/lib/ofx_br/parser.rb +72 -0
  18. data/lib/ofx_br/sign_on.rb +8 -0
  19. data/lib/ofx_br/statement.rb +5 -0
  20. data/lib/ofx_br/status.rb +12 -0
  21. data/lib/ofx_br/transaction.rb +16 -0
  22. data/lib/ofx_br/version.rb +8 -0
  23. data/lib/ofx_br.rb +33 -0
  24. data/ofx_br.gemspec +32 -0
  25. data/spec/fixtures/avatar.gif +0 -0
  26. data/spec/fixtures/bb.ofx +700 -0
  27. data/spec/fixtures/bradesco.ofx +96 -0
  28. data/spec/fixtures/creditcard.ofx +79 -0
  29. data/spec/fixtures/dtsof_balance_issue.ofx +54 -0
  30. data/spec/fixtures/error.ofx +24 -0
  31. data/spec/fixtures/invalid_version.ofx +308 -0
  32. data/spec/fixtures/nd-amex-sample.ofx +12 -0
  33. data/spec/fixtures/sample.ofx +315 -0
  34. data/spec/fixtures/santander.ofx +91 -0
  35. data/spec/fixtures/utf8.ofx +308 -0
  36. data/spec/fixtures/v103.ofx +80 -0
  37. data/spec/fixtures/v211.ofx +85 -0
  38. data/spec/ofx_br/account_spec.rb +131 -0
  39. data/spec/ofx_br/ofx102_spec.rb +67 -0
  40. data/spec/ofx_br/ofx103_spec.rb +50 -0
  41. data/spec/ofx_br/ofx211_spec.rb +84 -0
  42. data/spec/ofx_br/ofx_parser_spec.rb +123 -0
  43. data/spec/ofx_br/ofx_spec.rb +21 -0
  44. data/spec/ofx_br/sign_on_spec.rb +27 -0
  45. data/spec/ofx_br/statement_spec.rb +131 -0
  46. data/spec/ofx_br/status_spec.rb +47 -0
  47. data/spec/ofx_br/transaction_spec.rb +201 -0
  48. data/spec/spec_helper.rb +9 -0
  49. metadata +174 -0
@@ -0,0 +1,131 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Statement do
4
+ let(:parser) { ofx.parser }
5
+ let(:statement) { parser.statements.first }
6
+
7
+ context "Bank Account" do
8
+ let(:ofx) { OFX::Parser::Base.new("spec/fixtures/sample.ofx") }
9
+
10
+ it "returns currency" do
11
+ statement.currency.should == "BRL"
12
+ end
13
+
14
+ it "returns start date" do
15
+ statement.start_date.should == Time.parse("2009-10-09 08:00:00 +0000")
16
+ end
17
+
18
+ it "returns end date" do
19
+ statement.end_date.should == Time.parse("2009-11-03 08:00:00 +0000")
20
+ end
21
+
22
+ it "returns account" do
23
+ statement.account.should be_a(OFX::Account)
24
+ statement.account.id.should == '03227113109'
25
+ statement.account.type.should == :checking
26
+ end
27
+
28
+ it "returns transactions" do
29
+ statement.transactions.should be_a(Array)
30
+ statement.transactions.size.should == 36
31
+ end
32
+
33
+ describe "balance" do
34
+ let(:balance) { statement.balance }
35
+
36
+ it "returns balance" do
37
+ balance.amount.should == BigDecimal('598.44')
38
+ end
39
+
40
+ it "returns balance in pennies" do
41
+ balance.amount_in_pennies.should == 59844
42
+ end
43
+
44
+ it "returns balance date" do
45
+ balance.posted_at.should == Time.parse("2009-11-01 00:00:00 +0000")
46
+ end
47
+ end
48
+
49
+ describe "available_balance" do
50
+ let(:available_balance) { statement.available_balance }
51
+
52
+ it "returns available balance" do
53
+ available_balance.amount.should == BigDecimal('1555.99')
54
+ end
55
+
56
+ it "returns available balance in pennies" do
57
+ available_balance.amount_in_pennies.should == 155599
58
+ end
59
+
60
+ it "returns available balance date" do
61
+ available_balance.posted_at.should == Time.parse("2009-11-01 00:00:00 +0000")
62
+ end
63
+
64
+ context "when AVAILBAL not found" do
65
+ let(:ofx) { OFX::Parser::Base.new("spec/fixtures/utf8.ofx") }
66
+
67
+ it "returns nil " do
68
+ available_balance.should be_nil
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ context "Credit Card" do
75
+ let(:ofx) { OFX::Parser::Base.new("spec/fixtures/creditcard.ofx") }
76
+
77
+ it "returns currency" do
78
+ statement.currency.should == "USD"
79
+ end
80
+
81
+ it "returns start date" do
82
+ statement.start_date.should == Time.parse("2007-05-09 12:00:00 +0000")
83
+ end
84
+
85
+ it "returns end date" do
86
+ statement.end_date.should == Time.parse("2007-06-08 12:00:00 +0000")
87
+ end
88
+
89
+ it "returns account" do
90
+ statement.account.should be_a(OFX::Account)
91
+ statement.account.id.should == 'XXXXXXXXXXXX1111'
92
+ end
93
+
94
+ it "returns transactions" do
95
+ statement.transactions.should be_a(Array)
96
+ statement.transactions.size.should == 3
97
+ end
98
+
99
+ describe "balance" do
100
+ let(:balance) { statement.balance }
101
+
102
+ it "returns balance" do
103
+ balance.amount.should == BigDecimal('-1111.01')
104
+ end
105
+
106
+ it "returns balance in pennies" do
107
+ balance.amount_in_pennies.should == -111101
108
+ end
109
+
110
+ it "returns balance date" do
111
+ balance.posted_at.should == Time.parse("2007-06-23 19:20:13 +0000")
112
+ end
113
+ end
114
+
115
+ describe "available_balance" do
116
+ let(:available_balance) { statement.available_balance }
117
+
118
+ it "returns available balance" do
119
+ available_balance.amount.should == BigDecimal('19000.99')
120
+ end
121
+
122
+ it "returns available balance in pennies" do
123
+ available_balance.amount_in_pennies.should == 1900099
124
+ end
125
+
126
+ it "returns available balance date" do
127
+ available_balance.posted_at.should == Time.parse("2007-06-23 19:20:13 +0000")
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Status do
4
+ let(:ofx) { OFX::Parser::Base.new(ofx_file) }
5
+ let(:parser) { ofx.parser }
6
+ let(:status) { parser.sign_on.status }
7
+
8
+ context "success" do
9
+ let(:ofx_file) { "spec/fixtures/creditcard.ofx" }
10
+
11
+ it "should return code" do
12
+ status.code.should == 0
13
+ end
14
+
15
+ it "should return severity" do
16
+ status.severity.should == :info
17
+ end
18
+
19
+ it "should return message" do
20
+ status.message.should == ""
21
+ end
22
+
23
+ it "should be successful" do
24
+ status.success?.should == true
25
+ end
26
+ end
27
+
28
+ context "error" do
29
+ let(:ofx_file) { "spec/fixtures/error.ofx" }
30
+
31
+ it "should return code" do
32
+ status.code.should == 2000
33
+ end
34
+
35
+ it "should return severity" do
36
+ status.severity.should == :error
37
+ end
38
+
39
+ it "should return message" do
40
+ status.message.should == "We were unable to process your request. Please try again later."
41
+ end
42
+
43
+ it "should not be successful" do
44
+ status.success?.should == false
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,201 @@
1
+ require "spec_helper"
2
+
3
+ describe OFX::Transaction do
4
+ before do
5
+ @ofx = OFX::Parser::Base.new("spec/fixtures/sample.ofx")
6
+ @parser = @ofx.parser
7
+ @account = @parser.account
8
+ end
9
+
10
+ context "debit" do
11
+ before do
12
+ @transaction = @account.transactions[0]
13
+ end
14
+
15
+ it "should set amount" do
16
+ @transaction.amount.should == BigDecimal('-35.34')
17
+ end
18
+
19
+ it "should cast amount to BigDecimal" do
20
+ @transaction.amount.class.should == BigDecimal
21
+ end
22
+
23
+ it "should set amount in pennies" do
24
+ @transaction.amount_in_pennies.should == -3534
25
+ end
26
+
27
+ it "should set fit id" do
28
+ @transaction.fit_id.should == "200910091"
29
+ end
30
+
31
+ it "should set memo" do
32
+ @transaction.memo.should == "COMPRA VISA ELECTRON"
33
+ end
34
+
35
+ it "should set check number" do
36
+ @transaction.check_number.should == "0001223"
37
+ end
38
+
39
+ it "should have date" do
40
+ @transaction.posted_at.should == Time.parse("2009-10-09 08:00:00 +0000")
41
+ end
42
+
43
+ it 'should have user date' do
44
+ @transaction.occurred_at.should == Time.parse("2009-09-09 08:00:00 +0000")
45
+ end
46
+
47
+ it "should have type" do
48
+ @transaction.type.should == :debit
49
+ end
50
+
51
+ it "should have sic" do
52
+ @transaction.sic.should == '5072'
53
+ end
54
+ end
55
+
56
+ context "credit" do
57
+ before do
58
+ @transaction = @account.transactions[1]
59
+ end
60
+
61
+ it "should set amount" do
62
+ @transaction.amount.should == BigDecimal('60.39')
63
+ end
64
+
65
+ it "should set amount in pennies" do
66
+ @transaction.amount_in_pennies.should == 6039
67
+ end
68
+
69
+ it "should set fit id" do
70
+ @transaction.fit_id.should == "200910162"
71
+ end
72
+
73
+ it "should set memo" do
74
+ @transaction.memo.should == "DEPOSITO POUP.CORRENTE"
75
+ end
76
+
77
+ it "should set check number" do
78
+ @transaction.check_number.should == "0880136"
79
+ end
80
+
81
+ it "should have date" do
82
+ @transaction.posted_at.should == Time.parse("2009-10-16 08:00:00 +0000")
83
+ end
84
+
85
+ it "should have user date" do
86
+ @transaction.occurred_at.should == Time.parse("2009-09-16 08:00:00 +0000")
87
+ end
88
+
89
+ it "should have type" do
90
+ @transaction.type.should == :credit
91
+ end
92
+
93
+ it "should have empty sic" do
94
+ @transaction.sic.should == ''
95
+ end
96
+ end
97
+
98
+ context "with more info" do
99
+ before do
100
+ @transaction = @account.transactions[2]
101
+ end
102
+
103
+ it "should set payee" do
104
+ @transaction.payee.should == "Pagto conta telefone"
105
+ end
106
+
107
+ it "should set check number" do
108
+ @transaction.check_number.should == "000000101901"
109
+ end
110
+
111
+ it "should have date" do
112
+ @transaction.posted_at.should == Time.parse("2009-10-19 12:00:00 -0300")
113
+ end
114
+
115
+ it "should have user date" do
116
+ @transaction.occurred_at.should == Time.parse("2009-10-17 12:00:00 -0300")
117
+ end
118
+
119
+ it "should have type" do
120
+ @transaction.type.should == :other
121
+ end
122
+
123
+ it "should have reference number" do
124
+ @transaction.ref_number.should == "101.901"
125
+ end
126
+ end
127
+
128
+ context "with name" do
129
+ before do
130
+ @transaction = @account.transactions[3]
131
+ end
132
+
133
+ it "should set name" do
134
+ @transaction.name.should == "Pagto conta telefone"
135
+ end
136
+ end
137
+
138
+ context "with other types" do
139
+ before do
140
+ @ofx = OFX::Parser::Base.new("spec/fixtures/bb.ofx")
141
+ @parser = @ofx.parser
142
+ @account = @parser.account
143
+ end
144
+
145
+ it "should return dep" do
146
+ @transaction = @account.transactions[9]
147
+ @transaction.type.should == :dep
148
+ end
149
+
150
+ it "should return xfer" do
151
+ @transaction = @account.transactions[18]
152
+ @transaction.type.should == :xfer
153
+ end
154
+
155
+ it "should return cash" do
156
+ @transaction = @account.transactions[45]
157
+ @transaction.type.should == :cash
158
+ end
159
+
160
+ it "should return check" do
161
+ @transaction = @account.transactions[0]
162
+ @transaction.type.should == :check
163
+ end
164
+ end
165
+
166
+ context "decimal values using a comma" do
167
+ before do
168
+ @ofx = OFX::Parser::Base.new("spec/fixtures/santander.ofx")
169
+ @parser = @ofx.parser
170
+ @account = @parser.account
171
+ end
172
+
173
+ context "debit" do
174
+ before do
175
+ @transaction = @account.transactions[0]
176
+ end
177
+
178
+ it "should set amount" do
179
+ @transaction.amount.should == BigDecimal('-11.76')
180
+ end
181
+
182
+ it "should set amount in pennies" do
183
+ @transaction.amount_in_pennies.should == -1176
184
+ end
185
+ end
186
+
187
+ context "credit" do
188
+ before do
189
+ @transaction = @account.transactions[3]
190
+ end
191
+
192
+ it "should set amount" do
193
+ @transaction.amount.should == BigDecimal('47.01')
194
+ end
195
+
196
+ it "should set amount in pennies" do
197
+ @transaction.amount_in_pennies.should == 4701
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,9 @@
1
+ require 'ofx_br'
2
+
3
+ RSpec::Matchers.define :have_key do |key|
4
+ match do |hash|
5
+ hash.respond_to?(:keys) &&
6
+ hash.keys.is_a?(Array) &&
7
+ hash.keys.include?(key)
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ofx_br
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ - Anna Cruz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-09-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry-byebug
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.10'
70
+ description: " A simple OFX (Open Financial Exchange) parser built on top of Nokogiri.\n
71
+ \ Currently supports OFX 102, 200 and 211.\n \n Usage:\n \n OFX(\"sample.ofx\")
72
+ do |ofx|\n p ofx\n end\n"
73
+ email:
74
+ - fnando.vieira@gmail.com
75
+ - anna.cruz@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".github/dependabot.yml"
81
+ - ".gitignore"
82
+ - ".rspec"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - README.rdoc
87
+ - Rakefile
88
+ - lib/ofx_br.rb
89
+ - lib/ofx_br/account.rb
90
+ - lib/ofx_br/balance.rb
91
+ - lib/ofx_br/errors.rb
92
+ - lib/ofx_br/foundation.rb
93
+ - lib/ofx_br/parser.rb
94
+ - lib/ofx_br/parser/ofx102.rb
95
+ - lib/ofx_br/parser/ofx103.rb
96
+ - lib/ofx_br/parser/ofx211.rb
97
+ - lib/ofx_br/sign_on.rb
98
+ - lib/ofx_br/statement.rb
99
+ - lib/ofx_br/status.rb
100
+ - lib/ofx_br/transaction.rb
101
+ - lib/ofx_br/version.rb
102
+ - ofx_br.gemspec
103
+ - spec/fixtures/avatar.gif
104
+ - spec/fixtures/bb.ofx
105
+ - spec/fixtures/bradesco.ofx
106
+ - spec/fixtures/creditcard.ofx
107
+ - spec/fixtures/dtsof_balance_issue.ofx
108
+ - spec/fixtures/error.ofx
109
+ - spec/fixtures/invalid_version.ofx
110
+ - spec/fixtures/nd-amex-sample.ofx
111
+ - spec/fixtures/sample.ofx
112
+ - spec/fixtures/santander.ofx
113
+ - spec/fixtures/utf8.ofx
114
+ - spec/fixtures/v103.ofx
115
+ - spec/fixtures/v211.ofx
116
+ - spec/ofx_br/account_spec.rb
117
+ - spec/ofx_br/ofx102_spec.rb
118
+ - spec/ofx_br/ofx103_spec.rb
119
+ - spec/ofx_br/ofx211_spec.rb
120
+ - spec/ofx_br/ofx_parser_spec.rb
121
+ - spec/ofx_br/ofx_spec.rb
122
+ - spec/ofx_br/sign_on_spec.rb
123
+ - spec/ofx_br/statement_spec.rb
124
+ - spec/ofx_br/status_spec.rb
125
+ - spec/ofx_br/transaction_spec.rb
126
+ - spec/spec_helper.rb
127
+ homepage: http://rubygems.org/gems/ofx
128
+ licenses: []
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.2.15
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A simple OFX (Open Financial Exchange) parser built on top of Nokogiri. Currently
149
+ supports OFX 102, 200 and 211.
150
+ test_files:
151
+ - spec/fixtures/avatar.gif
152
+ - spec/fixtures/bb.ofx
153
+ - spec/fixtures/bradesco.ofx
154
+ - spec/fixtures/creditcard.ofx
155
+ - spec/fixtures/dtsof_balance_issue.ofx
156
+ - spec/fixtures/error.ofx
157
+ - spec/fixtures/invalid_version.ofx
158
+ - spec/fixtures/nd-amex-sample.ofx
159
+ - spec/fixtures/sample.ofx
160
+ - spec/fixtures/santander.ofx
161
+ - spec/fixtures/utf8.ofx
162
+ - spec/fixtures/v103.ofx
163
+ - spec/fixtures/v211.ofx
164
+ - spec/ofx_br/account_spec.rb
165
+ - spec/ofx_br/ofx102_spec.rb
166
+ - spec/ofx_br/ofx103_spec.rb
167
+ - spec/ofx_br/ofx211_spec.rb
168
+ - spec/ofx_br/ofx_parser_spec.rb
169
+ - spec/ofx_br/ofx_spec.rb
170
+ - spec/ofx_br/sign_on_spec.rb
171
+ - spec/ofx_br/statement_spec.rb
172
+ - spec/ofx_br/status_spec.rb
173
+ - spec/ofx_br/transaction_spec.rb
174
+ - spec/spec_helper.rb