organizze-ofx 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +41 -0
- data/README.rdoc +42 -0
- data/Rakefile +5 -0
- data/lib/ofx.rb +30 -0
- data/lib/ofx/account.rb +10 -0
- data/lib/ofx/balance.rb +7 -0
- data/lib/ofx/errors.rb +3 -0
- data/lib/ofx/foundation.rb +9 -0
- data/lib/ofx/parser.rb +71 -0
- data/lib/ofx/parser/ofx102.rb +111 -0
- data/lib/ofx/parser/ofx211.rb +40 -0
- data/lib/ofx/transaction.rb +14 -0
- data/lib/ofx/version.rb +8 -0
- data/ofx.gemspec +32 -0
- data/spec/fixtures/avatar.gif +0 -0
- data/spec/fixtures/bb.ofx +700 -0
- data/spec/fixtures/invalid_version.ofx +308 -0
- data/spec/fixtures/sample.ofx +309 -0
- data/spec/fixtures/utf8.ofx +308 -0
- data/spec/fixtures/v211.ofx +85 -0
- data/spec/ofx/account_spec.rb +44 -0
- data/spec/ofx/ofx102_spec.rb +42 -0
- data/spec/ofx/ofx211_spec.rb +75 -0
- data/spec/ofx/ofx_parser_spec.rb +102 -0
- data/spec/ofx/ofx_spec.rb +21 -0
- data/spec/ofx/transaction_spec.rb +146 -0
- data/spec/spec_helper.rb +9 -0
- metadata +139 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OFX::Parser::OFX211 do
|
4
|
+
before do
|
5
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/v211.ofx")
|
6
|
+
@parser = @ofx.parser
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a version" do
|
10
|
+
OFX::Parser::OFX211::VERSION.should == "2.1.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set headers" do
|
14
|
+
@parser.headers.should == @ofx.headers
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set body" do
|
18
|
+
@parser.body.should == @ofx.body
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set account" do
|
22
|
+
@parser.account.should be_a_kind_of(OFX::Account)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "transactions" do
|
26
|
+
before do
|
27
|
+
@transactions = @parser.account.transactions
|
28
|
+
end
|
29
|
+
|
30
|
+
# Test file contains only three transactions. Let's just check
|
31
|
+
# them all.
|
32
|
+
context "first" do
|
33
|
+
before do
|
34
|
+
@t = @transactions[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should contain the correct values" do
|
38
|
+
@t.amount.should == -80
|
39
|
+
@t.fit_id.should == "219378"
|
40
|
+
@t.memo.should be_empty
|
41
|
+
@t.posted_at.should == Time.parse("2005-08-24 08:00:00")
|
42
|
+
@t.name.should == "FrogKick Scuba Gear"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "second" do
|
47
|
+
before do
|
48
|
+
@t = @transactions[1]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should contain the correct values" do
|
52
|
+
@t.amount.should == -23
|
53
|
+
@t.fit_id.should == "219867"
|
54
|
+
@t.memo.should be_empty
|
55
|
+
@t.posted_at.should == Time.parse("2005-08-11 08:00:00")
|
56
|
+
@t.name.should == "Interest Charge"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "third" do
|
61
|
+
before do
|
62
|
+
@t = @transactions[2]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should contain the correct values" do
|
66
|
+
@t.amount.should == 350
|
67
|
+
@t.fit_id.should == "219868"
|
68
|
+
@t.memo.should be_empty
|
69
|
+
@t.posted_at.should == Time.parse("2005-08-11 08:00:00")
|
70
|
+
@t.name.should == "Payment - Thank You"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OFX::Parser do
|
4
|
+
before do
|
5
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/sample.ofx")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should accept file path" do
|
9
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/sample.ofx")
|
10
|
+
@ofx.content.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept file handler" do
|
14
|
+
file = open("spec/fixtures/sample.ofx")
|
15
|
+
@ofx = OFX::Parser::Base.new(file)
|
16
|
+
@ofx.content.should_not be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should accept file content" do
|
20
|
+
file = open("spec/fixtures/sample.ofx").read
|
21
|
+
@ofx = OFX::Parser::Base.new(file)
|
22
|
+
@ofx.content.should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set content" do
|
26
|
+
@ofx.content.should == open("spec/fixtures/sample.ofx").read
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should work with UTF8 and Latin1 encodings" do
|
30
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/utf8.ofx")
|
31
|
+
@ofx.content.should == open("spec/fixtures/utf8.ofx").read
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set body" do
|
35
|
+
@ofx.body.should_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise exception when trying to parse an unsupported OFX version" do
|
39
|
+
lambda {
|
40
|
+
OFX::Parser::Base.new("spec/fixtures/invalid_version.ofx")
|
41
|
+
}.should raise_error(OFX::UnsupportedFileError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should raise exception when trying to parse an invalid file" do
|
45
|
+
lambda {
|
46
|
+
OFX::Parser::Base.new("spec/fixtures/avatar.gif")
|
47
|
+
}.should raise_error(OFX::UnsupportedFileError)
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "headers" do
|
51
|
+
it "should have OFXHEADER" do
|
52
|
+
@ofx.headers["OFXHEADER"].should == "100"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have DATA" do
|
56
|
+
@ofx.headers["DATA"].should == "OFXSGML"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have VERSION" do
|
60
|
+
@ofx.headers["VERSION"].should == "102"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have SECURITY" do
|
64
|
+
@ofx.headers.should have_key("SECURITY")
|
65
|
+
@ofx.headers["SECURITY"].should be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have ENCODING" do
|
69
|
+
@ofx.headers["ENCODING"].should == "USASCII"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have CHARSET" do
|
73
|
+
@ofx.headers["CHARSET"].should == "1252"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have COMPRESSION" do
|
77
|
+
@ofx.headers.should have_key("COMPRESSION")
|
78
|
+
@ofx.headers["COMPRESSION"].should be_nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have OLDFILEUID" do
|
82
|
+
@ofx.headers.should have_key("OLDFILEUID")
|
83
|
+
@ofx.headers["OLDFILEUID"].should be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have NEWFILEUID" do
|
87
|
+
@ofx.headers.should have_key("NEWFILEUID")
|
88
|
+
@ofx.headers["NEWFILEUID"].should be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should parse headers with CR and without LF" do
|
92
|
+
@ofx = OFX::Parser::Base.new(ofx_with_carriage_return)
|
93
|
+
@ofx.headers.size.should be(9)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def ofx_with_carriage_return
|
98
|
+
header = %{OFXHEADER:100\rDATA:OFXSGML\rVERSION:102\rSECURITY:NONE\rENCODING:USASCII\rCHARSET:1252\rCOMPRESSION:NONE\rOLDFILEUID:NONE\rNEWFILEUID:NONE\r}
|
99
|
+
body = open("spec/fixtures/sample.ofx").read.split(/<OFX>/, 2)[1]
|
100
|
+
header + "<OFX>" + body
|
101
|
+
end
|
102
|
+
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,146 @@
|
|
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 == -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")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have type" do
|
44
|
+
@transaction.type.should == :debit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "credit" do
|
49
|
+
before do
|
50
|
+
@transaction = @account.transactions[1]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set amount" do
|
54
|
+
@transaction.amount.should == 60.39
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set amount in pennies" do
|
58
|
+
@transaction.amount_in_pennies.should == 6039
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set fit id" do
|
62
|
+
@transaction.fit_id.should == "200910162"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set memo" do
|
66
|
+
@transaction.memo.should == "DEPOSITO POUP.CORRENTE"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set check number" do
|
70
|
+
@transaction.check_number.should == "0880136"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have date" do
|
74
|
+
@transaction.posted_at.should == Time.parse("2009-10-16 08:00:00")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have type" do
|
78
|
+
@transaction.type.should == :credit
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with more info" do
|
83
|
+
before do
|
84
|
+
@transaction = @account.transactions[2]
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should set payee" do
|
88
|
+
@transaction.payee.should == "Pagto conta telefone"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should set check number" do
|
92
|
+
@transaction.check_number.should == "000000101901"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should have date" do
|
96
|
+
@transaction.posted_at.should == Time.parse("2009-10-19 12:00:00")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have type" do
|
100
|
+
@transaction.type.should == :other
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should have reference number" do
|
104
|
+
@transaction.ref_number.should == "101.901"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with name" do
|
109
|
+
before do
|
110
|
+
@transaction = @account.transactions[3]
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should set name" do
|
114
|
+
@transaction.name.should == "Pagto conta telefone"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with other types" do
|
119
|
+
|
120
|
+
before do
|
121
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/bb.ofx")
|
122
|
+
@parser = @ofx.parser
|
123
|
+
@account = @parser.account
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return dep" do
|
127
|
+
@transaction = @account.transactions[9]
|
128
|
+
@transaction.type.should == :dep
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should return xfer" do
|
132
|
+
@transaction = @account.transactions[18]
|
133
|
+
@transaction.type.should == :xfer
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return cash" do
|
137
|
+
@transaction = @account.transactions[45]
|
138
|
+
@transaction.type.should == :cash
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return check" do
|
142
|
+
@transaction = @account.transactions[0]
|
143
|
+
@transaction.type.should == :check
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: organizze-ofx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nando Vieira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-04 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: nokogiri
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "2.6"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: ruby-debug19
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description: |
|
50
|
+
A simple OFX (Open Financial Exchange) parser built on top of Nokogiri.
|
51
|
+
Currently supports OFX 102, 200 and 211.
|
52
|
+
|
53
|
+
Usage:
|
54
|
+
|
55
|
+
OFX("sample.ofx") do |ofx|
|
56
|
+
p ofx
|
57
|
+
end
|
58
|
+
|
59
|
+
email:
|
60
|
+
- fnando.vieira@gmail.com
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
extra_rdoc_files: []
|
66
|
+
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- .rspec
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- README.rdoc
|
73
|
+
- Rakefile
|
74
|
+
- lib/ofx.rb
|
75
|
+
- lib/ofx/account.rb
|
76
|
+
- lib/ofx/balance.rb
|
77
|
+
- lib/ofx/errors.rb
|
78
|
+
- lib/ofx/foundation.rb
|
79
|
+
- lib/ofx/parser.rb
|
80
|
+
- lib/ofx/parser/ofx102.rb
|
81
|
+
- lib/ofx/parser/ofx211.rb
|
82
|
+
- lib/ofx/transaction.rb
|
83
|
+
- lib/ofx/version.rb
|
84
|
+
- ofx.gemspec
|
85
|
+
- spec/fixtures/avatar.gif
|
86
|
+
- spec/fixtures/bb.ofx
|
87
|
+
- spec/fixtures/invalid_version.ofx
|
88
|
+
- spec/fixtures/sample.ofx
|
89
|
+
- spec/fixtures/utf8.ofx
|
90
|
+
- spec/fixtures/v211.ofx
|
91
|
+
- spec/ofx/account_spec.rb
|
92
|
+
- spec/ofx/ofx102_spec.rb
|
93
|
+
- spec/ofx/ofx211_spec.rb
|
94
|
+
- spec/ofx/ofx_parser_spec.rb
|
95
|
+
- spec/ofx/ofx_spec.rb
|
96
|
+
- spec/ofx/transaction_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://rubygems.org/gems/ofx
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.5.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: A simple OFX (Open Financial Exchange) parser built on top of Nokogiri. Currently supports OFX 102, 200 and 211.
|
126
|
+
test_files:
|
127
|
+
- spec/fixtures/avatar.gif
|
128
|
+
- spec/fixtures/bb.ofx
|
129
|
+
- spec/fixtures/invalid_version.ofx
|
130
|
+
- spec/fixtures/sample.ofx
|
131
|
+
- spec/fixtures/utf8.ofx
|
132
|
+
- spec/fixtures/v211.ofx
|
133
|
+
- spec/ofx/account_spec.rb
|
134
|
+
- spec/ofx/ofx102_spec.rb
|
135
|
+
- spec/ofx/ofx211_spec.rb
|
136
|
+
- spec/ofx/ofx_parser_spec.rb
|
137
|
+
- spec/ofx/ofx_spec.rb
|
138
|
+
- spec/ofx/transaction_spec.rb
|
139
|
+
- spec/spec_helper.rb
|