ofx_reader 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/ofx_reader/errors/unsupported_ofx_version_error.rb +2 -0
- data/lib/ofx_reader/parser/base.rb +18 -13
- data/lib/ofx_reader/parser/ofx_102.rb +7 -19
- data/lib/ofx_reader/version.rb +1 -1
- data/lib/ofx_reader.rb +19 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412056e9bc0138a1aa7612277e4678942fa1e8a514ef3af9c84133e337cba320
|
4
|
+
data.tar.gz: c2a011b0b3d7002fecc96b7923bf827969fb9c7db28e5deb02bb59dad2da1bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f4a500d8b8d3d7dccc9601d1a97ab572c7d4506a990ed0198b1e004a70aa3987a196467c5d30d09ad6561fcb6b6ce9e93fec3a16aa3ae6fdd74c414e67aa2cb
|
7
|
+
data.tar.gz: 74c34eb7b255ab0438d5ba9bacc9861efc45734ff0f079f88cecf3ad129f0e7671dca56e3875ab02c1e0304d8987136c22dbf75a0ab300a55ac070594e4e8493
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,36 +4,41 @@ module OFXReader
|
|
4
4
|
require 'nokogiri'
|
5
5
|
require 'time'
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :header, :body
|
8
|
+
attr_reader :headers, :account, :transactions
|
8
9
|
|
9
10
|
def initialize(content)
|
10
|
-
|
11
|
-
@
|
11
|
+
content = content.encode("UTF-8", "ISO-8859-1")
|
12
|
+
@header, @body = content.dup.split(/(?=<OFX>)/, 2)
|
13
|
+
@headers = parse_headers(header)
|
14
|
+
@account, @transactions = parse_body(body)
|
12
15
|
end
|
13
16
|
|
14
17
|
private
|
15
18
|
|
16
|
-
def read(content)
|
17
|
-
headers, body = content.dup.split(/(?=<OFX>)/, 2)
|
18
|
-
headers = parse_headers(headers)
|
19
|
-
body = parse_body(body)
|
20
|
-
[headers, body]
|
21
|
-
end
|
22
|
-
|
23
19
|
def parse_headers(headers)
|
24
20
|
headers.each_line.with_object({}) do |line, hash|
|
25
21
|
_, k, v = *line.match(/^(.*?):(.*?)\s*(\r?\n)*$/)
|
26
|
-
hash[k] = v unless v.nil?
|
22
|
+
hash[k.downcase.to_sym] = v unless v.nil?
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
26
|
def parse_body(body)
|
31
|
-
# body.prepend('<OFX>')
|
32
27
|
body.gsub!(/>\s+</m, '><')
|
33
28
|
body.gsub!(/\s+</m, '<')
|
34
29
|
body.gsub!(/>\s+/m, '>')
|
35
30
|
body.gsub!(/<(\w+?)>([^<]+)/m, '<\1>\2</\1>')
|
36
|
-
|
31
|
+
parser.new(::Nokogiri::XML(body)).parse
|
32
|
+
end
|
33
|
+
|
34
|
+
def parser
|
35
|
+
# TODO: Provide support to other formats
|
36
|
+
case headers[:version]
|
37
|
+
when /10(2|3)/
|
38
|
+
OFXReader::Parser::OFX102
|
39
|
+
else
|
40
|
+
raise UnsupportedOFXVersionError
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -1,31 +1,19 @@
|
|
1
1
|
module OFXReader
|
2
2
|
module Parser
|
3
|
-
class OFX102 <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
"SAVINGS",
|
8
|
-
"CREDITCARD",
|
9
|
-
"CREDITLINE",
|
10
|
-
"INVESTMENT",
|
11
|
-
"MONEYMRKT",
|
12
|
-
]
|
13
|
-
|
14
|
-
TRANSACTION_TYPES = [
|
15
|
-
'ATM', 'CASH', 'CHECK', 'CREDIT', 'DEBIT', 'DEP', 'DIRECTDEBIT',
|
16
|
-
'DIRECTDEP', 'DIV', 'FEE', 'INT', 'OTHER', 'PAYMENT', 'POS',
|
17
|
-
'REPEATPMT', 'SRVCHG', 'XFER',
|
18
|
-
].inject({}) { |hash, type| hash.tap { |h| h[type] = type.downcase } }
|
3
|
+
class OFX102 < Struct.new(:ofx_body)
|
4
|
+
def parse
|
5
|
+
[account, transactions]
|
6
|
+
end
|
19
7
|
|
20
8
|
def account
|
21
9
|
{
|
22
|
-
bank_id:
|
23
|
-
account_id:
|
10
|
+
bank_id: ofx_body.search('BANKACCTFROM BANKID').inner_text,
|
11
|
+
account_id: ofx_body.search('BANKACCTFROM ACCTID').inner_text,
|
24
12
|
}
|
25
13
|
end
|
26
14
|
|
27
15
|
def transactions
|
28
|
-
|
16
|
+
ofx_body.search('BANKTRANLIST STMTTRN').map do |node|
|
29
17
|
build_transaction(node)
|
30
18
|
end
|
31
19
|
end
|
data/lib/ofx_reader/version.rb
CHANGED
data/lib/ofx_reader.rb
CHANGED
@@ -5,9 +5,27 @@ begin
|
|
5
5
|
rescue LoadError
|
6
6
|
end
|
7
7
|
|
8
|
+
require "ofx_reader/errors/unsupported_ofx_version_error"
|
8
9
|
require "ofx_reader/parser/base"
|
9
10
|
require "ofx_reader/parser/ofx_102"
|
10
11
|
|
11
12
|
module OFXReader
|
12
|
-
|
13
|
+
# ACCOUNT_TYPES = [
|
14
|
+
# "CHECKING",
|
15
|
+
# "SAVINGS",
|
16
|
+
# "CREDITCARD",
|
17
|
+
# "CREDITLINE",
|
18
|
+
# "INVESTMENT",
|
19
|
+
# "MONEYMRKT",
|
20
|
+
# ]
|
21
|
+
#
|
22
|
+
# TRANSACTION_TYPES = [
|
23
|
+
# 'ATM', 'CASH', 'CHECK', 'CREDIT', 'DEBIT', 'DEP', 'DIRECTDEBIT',
|
24
|
+
# 'DIRECTDEP', 'DIV', 'FEE', 'INT', 'OTHER', 'PAYMENT', 'POS',
|
25
|
+
# 'REPEATPMT', 'SRVCHG', 'XFER',
|
26
|
+
# ]
|
27
|
+
|
28
|
+
def self.call(ofx_text)
|
29
|
+
OFXReader::Parser::Base.new(ofx_text)
|
30
|
+
end
|
13
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ofx_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francisco Martins
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- exe/ofx_reader
|
101
101
|
- lib/ofx_reader.rb
|
102
|
+
- lib/ofx_reader/errors/unsupported_ofx_version_error.rb
|
102
103
|
- lib/ofx_reader/parser/base.rb
|
103
104
|
- lib/ofx_reader/parser/ofx_102.rb
|
104
105
|
- lib/ofx_reader/version.rb
|