aranha-parsers 0.26.3 → 0.28.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.
- checksums.yaml +4 -4
- data/lib/aranha/parsers/html/node/default/nodes_support.rb +16 -0
- data/lib/aranha/parsers/ofx/body_parser/node_extension.rb +42 -0
- data/lib/aranha/parsers/ofx/body_parser.rb +31 -0
- data/lib/aranha/parsers/ofx/data/account.rb +13 -0
- data/lib/aranha/parsers/ofx/data/account_info.rb +13 -0
- data/lib/aranha/parsers/ofx/data/bank_account.rb +24 -0
- data/lib/aranha/parsers/ofx/data/credit_account.rb +18 -0
- data/lib/aranha/parsers/ofx/data/institute.rb +13 -0
- data/lib/aranha/parsers/ofx/data/investment_account.rb +18 -0
- data/lib/aranha/parsers/ofx/data/monetary_class_support.rb +18 -0
- data/lib/aranha/parsers/ofx/data/monetary_support.rb +45 -0
- data/lib/aranha/parsers/ofx/data/position.rb +12 -0
- data/lib/aranha/parsers/ofx/data/sign_on.rb +13 -0
- data/lib/aranha/parsers/ofx/data/statement.rb +13 -0
- data/lib/aranha/parsers/ofx/data/status.rb +32 -0
- data/lib/aranha/parsers/ofx/data/transaction.rb +57 -0
- data/lib/aranha/parsers/ofx/data.rb +25 -0
- data/lib/aranha/parsers/ofx/mcc.rb +676 -0
- data/lib/aranha/parsers/ofx/parser.rb +183 -0
- data/lib/aranha/parsers/version.rb +1 -1
- data/lib/aranha/parsers.rb +1 -5
- metadata +29 -38
- data/lib/aranha/parsers/patches/ofx_parser.rb +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 301d8d022004d83c27be9117139de33ab99c01bde0e090571f537efd49b633e1
|
|
4
|
+
data.tar.gz: 3e10a85285cbb20b2d028b4b38c72e54efff4a18c2e3c9947873da9fc3482441
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 732464027e20b3aac0974a1590318553bebeff61828f8aba0cec7c8b5f7e10de88b93e5d9dce26bf7964b6c1a54e6c8a984267e4791a9b371f56dc88b8c7cdab
|
|
7
|
+
data.tar.gz: 6cb38269b61d86cfca3a059b9bd8761c90abb4136cb4eeeedb2e38ac32927d7d6b1d4fba01598467a5235571a6fc558d6c8d82452410862ade220aaf644c7a9e
|
|
@@ -19,6 +19,22 @@ module Aranha
|
|
|
19
19
|
def node_value(node, xpath)
|
|
20
20
|
node.at_xpath(xpath)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
# @param node [Nokogiri::XML::Node]
|
|
24
|
+
# @param xpath [String]
|
|
25
|
+
# @return [String]
|
|
26
|
+
def node_xml_value(node, xpath)
|
|
27
|
+
found = node_value(node, xpath)
|
|
28
|
+
found ? found.to_xml : ''
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @param node [Nokogiri::XML::Node]
|
|
32
|
+
# @param xpath [String]
|
|
33
|
+
# @return [String]
|
|
34
|
+
def node_set_xml_value(node, xpath)
|
|
35
|
+
found = node_set_value(node, xpath)
|
|
36
|
+
found ? found.to_xml : ''
|
|
37
|
+
end
|
|
22
38
|
end
|
|
23
39
|
end
|
|
24
40
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module Aranha
|
|
6
|
+
module Parsers
|
|
7
|
+
module Ofx
|
|
8
|
+
class BodyParser
|
|
9
|
+
module NodeExtension
|
|
10
|
+
def collect(&block)
|
|
11
|
+
r = []
|
|
12
|
+
each do |e|
|
|
13
|
+
r << block.call(prepend_extension(e))
|
|
14
|
+
end
|
|
15
|
+
r
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def inner_text(*args)
|
|
19
|
+
normalize_text(super)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
alias text inner_text
|
|
23
|
+
|
|
24
|
+
def prepend_extension(object)
|
|
25
|
+
object.singleton_class.prepend(::Aranha::Parsers::Ofx::BodyParser::NodeExtension)
|
|
26
|
+
object
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def normalize_text(text)
|
|
30
|
+
text.gsub(/\s+/, ' ').strip
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def search(*args)
|
|
34
|
+
prepend_extension(super)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
alias / search
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module Aranha
|
|
6
|
+
module Parsers
|
|
7
|
+
module Ofx
|
|
8
|
+
class BodyParser
|
|
9
|
+
class << self
|
|
10
|
+
# @param content [String]
|
|
11
|
+
# @return [Nokogiri::XML::Document]
|
|
12
|
+
def parse(content)
|
|
13
|
+
new(content).parse
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
common_constructor :content
|
|
18
|
+
|
|
19
|
+
# @return [Nokogiri::XML::Document]
|
|
20
|
+
def parse
|
|
21
|
+
r = ::Nokogiri::XML(content) do |config|
|
|
22
|
+
config.strict
|
|
23
|
+
config.noblanks
|
|
24
|
+
end
|
|
25
|
+
r.singleton_class.prepend(::Aranha::Parsers::Ofx::BodyParser::NodeExtension)
|
|
26
|
+
r
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
class BankAccount < ::Aranha::Parsers::Ofx::Data::Account
|
|
8
|
+
TYPE = %i[CHECKING SAVINGS MONEYMRKT CREDITLINE].freeze
|
|
9
|
+
attr_accessor :type, :balance, :balance_date
|
|
10
|
+
|
|
11
|
+
include ::Aranha::Parsers::Ofx::Data::MonetarySupport
|
|
12
|
+
extend ::Aranha::Parsers::Ofx::Data::MonetaryClassSupport
|
|
13
|
+
|
|
14
|
+
monetary_vars :balance
|
|
15
|
+
|
|
16
|
+
undef type
|
|
17
|
+
def type # rubocop:disable Lint/DuplicateMethods
|
|
18
|
+
@type.to_s.upcase.to_sym
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
class CreditAccount < ::Aranha::Parsers::Ofx::Data::Account
|
|
8
|
+
attr_accessor :remaining_credit, :remaining_credit_date, :balance, :balance_date
|
|
9
|
+
|
|
10
|
+
include ::Aranha::Parsers::Ofx::Data::MonetarySupport
|
|
11
|
+
extend ::Aranha::Parsers::Ofx::Data::MonetaryClassSupport
|
|
12
|
+
|
|
13
|
+
monetary_vars :remaining_credit, :balance
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
class InvestmentAccount < ::Aranha::Parsers::Ofx::Data::Account
|
|
8
|
+
attr_accessor :broker_id, :positions, :margin_balance, :short_balance, :cash_balance
|
|
9
|
+
|
|
10
|
+
include ::Aranha::Parsers::Ofx::Data::MonetarySupport
|
|
11
|
+
extend ::Aranha::Parsers::Ofx::Data::MonetaryClassSupport
|
|
12
|
+
|
|
13
|
+
monetary_vars :margin_balance, :short_balance, :cash_balance
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
module MonetaryClassSupport
|
|
8
|
+
attr_accessor :monies
|
|
9
|
+
|
|
10
|
+
def monetary_vars(*methods) # :nodoc:
|
|
11
|
+
self.monies ||= []
|
|
12
|
+
self.monies += methods
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
module MonetarySupport
|
|
8
|
+
# Returns pennies for a given string amount, i.e:
|
|
9
|
+
# '-123.45' => -12345
|
|
10
|
+
# '123' => 12300
|
|
11
|
+
def pennies_for(amount)
|
|
12
|
+
return nil if amount == ''
|
|
13
|
+
|
|
14
|
+
int, fraction = amount.scan(/\d+/)
|
|
15
|
+
i = fraction.to_s.strip =~ /[1-9]/ ? "#{int}#{fraction[0, 2]}".to_i : int.to_i * 100
|
|
16
|
+
amount =~ /^\s*-\s*\d+/ ? -i : i
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def original_method(meth) # :nodoc:
|
|
20
|
+
meth.to_s.sub('_in_pennies', '').to_sym
|
|
21
|
+
rescue StandardError
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def monetary_method_call?(meth) # :nodoc:
|
|
26
|
+
orig = original_method(meth)
|
|
27
|
+
self.class.monies.include?(orig) && meth.to_s == "#{orig}_in_pennies"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def method_missing(meth, *args) # :nodoc: # rubocop:disable Style/MissingRespondToMissing
|
|
31
|
+
if monetary_method_call?(meth)
|
|
32
|
+
pennies_for(send(original_method(meth)))
|
|
33
|
+
else
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def respond_to?(meth) # :nodoc:
|
|
39
|
+
monetary_method_call?(meth) || super
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
# Status of a sign on
|
|
8
|
+
class Status
|
|
9
|
+
attr_accessor :code, :severity, :message
|
|
10
|
+
|
|
11
|
+
CODES = {
|
|
12
|
+
'0' => 'Success',
|
|
13
|
+
'2000' => 'General error',
|
|
14
|
+
'15000' => 'Must change USERPASS',
|
|
15
|
+
'15500' => 'Signon invalid',
|
|
16
|
+
'15501' => 'Customer account already in use',
|
|
17
|
+
'15502' => 'USERPASS Lockout'
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
def code_desc
|
|
21
|
+
CODES[code]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
undef code
|
|
25
|
+
def code # rubocop:disable Lint/DuplicateMethods
|
|
26
|
+
@code.to_s.strip
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
class Data
|
|
7
|
+
class Transaction
|
|
8
|
+
attr_accessor :type, :date, :amount, :fit_id, :check_number, :sic, :memo, :payee,
|
|
9
|
+
:currate, :cursym
|
|
10
|
+
|
|
11
|
+
include ::Aranha::Parsers::Ofx::Data::MonetarySupport
|
|
12
|
+
extend ::Aranha::Parsers::Ofx::Data::MonetaryClassSupport
|
|
13
|
+
|
|
14
|
+
monetary_vars :amount
|
|
15
|
+
|
|
16
|
+
TYPE = {
|
|
17
|
+
CREDIT: 'Generic credit',
|
|
18
|
+
DEBIT: 'Generic debit',
|
|
19
|
+
INT: 'Interest earned or paid ',
|
|
20
|
+
DIV: 'Dividend',
|
|
21
|
+
FEE: 'FI fee',
|
|
22
|
+
SRVCHG: 'Service charge',
|
|
23
|
+
DEP: 'Deposit',
|
|
24
|
+
ATM: 'ATM debit or credit',
|
|
25
|
+
POS: 'Point of sale debit or credit ',
|
|
26
|
+
XFER: 'Transfer',
|
|
27
|
+
CHECK: 'Check',
|
|
28
|
+
PAYMENT: 'Electronic payment',
|
|
29
|
+
CASH: 'Cash withdrawal',
|
|
30
|
+
DIRECTDEP: 'Direct deposit',
|
|
31
|
+
DIRECTDEBIT: 'Merchant initiated debit',
|
|
32
|
+
REPEATPMT: 'Repeating payment/standing order',
|
|
33
|
+
OTHER: 'Other'
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
def type_desc
|
|
37
|
+
TYPE[type]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
undef type
|
|
41
|
+
def type # rubocop:disable Lint/DuplicateMethods
|
|
42
|
+
@type.to_s.strip.upcase.to_sym
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
undef sic
|
|
46
|
+
def sic # rubocop:disable Lint/DuplicateMethods
|
|
47
|
+
@sic == '' ? nil : @sic
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def sic_desc
|
|
51
|
+
::Aranha::Parsers::Ofx::Mcc::CODES[sic]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aranha
|
|
4
|
+
module Parsers
|
|
5
|
+
module Ofx
|
|
6
|
+
# This class is returned when a parse is successful.
|
|
7
|
+
# == General Notes
|
|
8
|
+
# * currency symbols are an iso4217 3-letter code
|
|
9
|
+
# * language is defined by iso639 3-letter code
|
|
10
|
+
class Data
|
|
11
|
+
attr_accessor :header, :sign_on, :signup_account_info,
|
|
12
|
+
:bank_account, :credit_card, :investment
|
|
13
|
+
|
|
14
|
+
def accounts
|
|
15
|
+
accounts = []
|
|
16
|
+
%i[bank_account credit_card investment].each do |method|
|
|
17
|
+
val = send(method)
|
|
18
|
+
accounts << val if val
|
|
19
|
+
end
|
|
20
|
+
accounts
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|