chopmo-ofx 0.3.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.
- data/.gitignore +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/README.rdoc +42 -0
- data/Rakefile +5 -0
- data/lib/ofx.rb +29 -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 +69 -0
- data/lib/ofx/parser/ofx102.rb +113 -0
- data/lib/ofx/parser/ofx211.rb +42 -0
- data/lib/ofx/transaction.rb +14 -0
- data/lib/ofx/version.rb +8 -0
- data/ofx.gemspec +31 -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 +29 -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 +148 -0
- data/spec/spec_helper.rb +9 -0
- metadata +146 -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,148 @@
|
|
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
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chopmo-ofx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nando Vieira
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-24 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 15
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 2.0.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: |
|
52
|
+
A simple OFX (Open Financial Exchange) parser built on top of Nokogiri.
|
53
|
+
Currently supports OFX 1.0.2.
|
54
|
+
|
55
|
+
Usage:
|
56
|
+
|
57
|
+
OFX("sample.ofx") do |ofx|
|
58
|
+
p ofx
|
59
|
+
end
|
60
|
+
|
61
|
+
email:
|
62
|
+
- fnando.vieira@gmail.com
|
63
|
+
executables: []
|
64
|
+
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- README.rdoc
|
74
|
+
- Rakefile
|
75
|
+
- lib/ofx.rb
|
76
|
+
- lib/ofx/account.rb
|
77
|
+
- lib/ofx/balance.rb
|
78
|
+
- lib/ofx/errors.rb
|
79
|
+
- lib/ofx/foundation.rb
|
80
|
+
- lib/ofx/parser.rb
|
81
|
+
- lib/ofx/parser/ofx102.rb
|
82
|
+
- lib/ofx/parser/ofx211.rb
|
83
|
+
- lib/ofx/transaction.rb
|
84
|
+
- lib/ofx/version.rb
|
85
|
+
- ofx.gemspec
|
86
|
+
- spec/fixtures/avatar.gif
|
87
|
+
- spec/fixtures/bb.ofx
|
88
|
+
- spec/fixtures/invalid_version.ofx
|
89
|
+
- spec/fixtures/sample.ofx
|
90
|
+
- spec/fixtures/utf8.ofx
|
91
|
+
- spec/fixtures/v211.ofx
|
92
|
+
- spec/ofx/account_spec.rb
|
93
|
+
- spec/ofx/ofx102_spec.rb
|
94
|
+
- spec/ofx/ofx211_spec.rb
|
95
|
+
- spec/ofx/ofx_parser_spec.rb
|
96
|
+
- spec/ofx/ofx_spec.rb
|
97
|
+
- spec/ofx/transaction_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: http://rubygems.org/gems/ofx
|
101
|
+
licenses: []
|
102
|
+
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.4.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: A simple OFX (Open Financial Exchange) parser built on top of Nokogiri. Currently supports OFX 1.0.2.
|
133
|
+
test_files:
|
134
|
+
- spec/fixtures/avatar.gif
|
135
|
+
- spec/fixtures/bb.ofx
|
136
|
+
- spec/fixtures/invalid_version.ofx
|
137
|
+
- spec/fixtures/sample.ofx
|
138
|
+
- spec/fixtures/utf8.ofx
|
139
|
+
- spec/fixtures/v211.ofx
|
140
|
+
- spec/ofx/account_spec.rb
|
141
|
+
- spec/ofx/ofx102_spec.rb
|
142
|
+
- spec/ofx/ofx211_spec.rb
|
143
|
+
- spec/ofx/ofx_parser_spec.rb
|
144
|
+
- spec/ofx/ofx_spec.rb
|
145
|
+
- spec/ofx/transaction_spec.rb
|
146
|
+
- spec/spec_helper.rb
|