ofx_kit 0.1.0 → 1.0.1
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/README.md +42 -82
- data/lib/generators/{ofx → ofx_kit}/eject_generator.rb +5 -3
- data/lib/ofx_kit/balance.rb +25 -0
- data/lib/ofx_kit/bank_account.rb +25 -0
- data/lib/ofx_kit/{domain/bank_statement.rb → bank_statement.rb} +1 -0
- data/lib/ofx_kit/base/account.rb +3 -0
- data/lib/ofx_kit/base/builder.rb +8 -4
- data/lib/ofx_kit/base/document.rb +16 -4
- data/lib/ofx_kit/base/entity.rb +15 -5
- data/lib/ofx_kit/base/statement.rb +19 -1
- data/lib/ofx_kit/configuration/core.rb +75 -28
- data/lib/ofx_kit/configuration/date_parser.rb +1 -1
- data/lib/ofx_kit/configuration/mapping_applicator.rb +5 -3
- data/lib/ofx_kit/configuration/section_proxy.rb +14 -5
- data/lib/ofx_kit/{domain/credit_card_account.rb → credit_card_account.rb} +1 -0
- data/lib/ofx_kit/{domain/credit_card_statement.rb → credit_card_statement.rb} +1 -0
- data/lib/ofx_kit/errors/configuration_error.rb +8 -0
- data/lib/ofx_kit/errors/encoding_error.rb +8 -0
- data/lib/ofx_kit/errors/error.rb +11 -0
- data/lib/ofx_kit/errors/invalid_body_error.rb +8 -0
- data/lib/ofx_kit/errors/invalid_header_error.rb +8 -0
- data/lib/ofx_kit/errors/multiple_statements_error.rb +8 -0
- data/lib/ofx_kit/errors/parse_error.rb +8 -0
- data/lib/ofx_kit/errors/unsupported_version_error.rb +20 -0
- data/lib/ofx_kit/parser.rb +81 -29
- data/lib/ofx_kit/tokenizer/base.rb +11 -6
- data/lib/ofx_kit/tokenizer/ofx1.rb +2 -2
- data/lib/ofx_kit/tokenizer/ofx2.rb +1 -1
- data/lib/ofx_kit/transaction.rb +45 -0
- data/lib/ofx_kit/transaction_collection.rb +126 -0
- data/lib/ofx_kit/version.rb +2 -1
- data/lib/ofx_kit.rb +43 -24
- metadata +36 -13
- data/lib/ofx_kit/configuration.rb +0 -6
- data/lib/ofx_kit/domain/balance.rb +0 -10
- data/lib/ofx_kit/domain/bank_account.rb +0 -8
- data/lib/ofx_kit/domain/transaction.rb +0 -13
- data/lib/ofx_kit/domain/transaction_collection.rb +0 -94
- data/lib/ofx_kit/errors.rb +0 -36
- /data/lib/generators/{ofx → ofx_kit}/templates/ofx_mappings.yml +0 -0
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ofx_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucas Geron
|
|
@@ -65,6 +65,20 @@ dependencies:
|
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '13.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rdoc
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 7.2.0
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 7.2.0
|
|
68
82
|
- !ruby/object:Gem::Dependency
|
|
69
83
|
name: rspec
|
|
70
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -102,39 +116,48 @@ extra_rdoc_files: []
|
|
|
102
116
|
files:
|
|
103
117
|
- LICENSE
|
|
104
118
|
- README.md
|
|
105
|
-
- lib/generators/
|
|
106
|
-
- lib/generators/
|
|
119
|
+
- lib/generators/ofx_kit/eject_generator.rb
|
|
120
|
+
- lib/generators/ofx_kit/templates/ofx_mappings.yml
|
|
107
121
|
- lib/ofx_kit.rb
|
|
122
|
+
- lib/ofx_kit/balance.rb
|
|
123
|
+
- lib/ofx_kit/bank_account.rb
|
|
124
|
+
- lib/ofx_kit/bank_statement.rb
|
|
108
125
|
- lib/ofx_kit/base/account.rb
|
|
109
126
|
- lib/ofx_kit/base/builder.rb
|
|
110
127
|
- lib/ofx_kit/base/document.rb
|
|
111
128
|
- lib/ofx_kit/base/entity.rb
|
|
112
129
|
- lib/ofx_kit/base/statement.rb
|
|
113
|
-
- lib/ofx_kit/configuration.rb
|
|
114
130
|
- lib/ofx_kit/configuration/core.rb
|
|
115
131
|
- lib/ofx_kit/configuration/date_parser.rb
|
|
116
132
|
- lib/ofx_kit/configuration/mapping_applicator.rb
|
|
117
133
|
- lib/ofx_kit/configuration/section_proxy.rb
|
|
118
|
-
- lib/ofx_kit/
|
|
119
|
-
- lib/ofx_kit/
|
|
120
|
-
- lib/ofx_kit/
|
|
121
|
-
- lib/ofx_kit/
|
|
122
|
-
- lib/ofx_kit/
|
|
123
|
-
- lib/ofx_kit/
|
|
124
|
-
- lib/ofx_kit/
|
|
125
|
-
- lib/ofx_kit/errors.rb
|
|
134
|
+
- lib/ofx_kit/credit_card_account.rb
|
|
135
|
+
- lib/ofx_kit/credit_card_statement.rb
|
|
136
|
+
- lib/ofx_kit/errors/configuration_error.rb
|
|
137
|
+
- lib/ofx_kit/errors/encoding_error.rb
|
|
138
|
+
- lib/ofx_kit/errors/error.rb
|
|
139
|
+
- lib/ofx_kit/errors/invalid_body_error.rb
|
|
140
|
+
- lib/ofx_kit/errors/invalid_header_error.rb
|
|
141
|
+
- lib/ofx_kit/errors/multiple_statements_error.rb
|
|
142
|
+
- lib/ofx_kit/errors/parse_error.rb
|
|
143
|
+
- lib/ofx_kit/errors/unsupported_version_error.rb
|
|
126
144
|
- lib/ofx_kit/mappings/core_mappings.yml
|
|
127
145
|
- lib/ofx_kit/mappings/field_mappings.yml
|
|
128
146
|
- lib/ofx_kit/parser.rb
|
|
129
147
|
- lib/ofx_kit/tokenizer/base.rb
|
|
130
148
|
- lib/ofx_kit/tokenizer/ofx1.rb
|
|
131
149
|
- lib/ofx_kit/tokenizer/ofx2.rb
|
|
150
|
+
- lib/ofx_kit/transaction.rb
|
|
151
|
+
- lib/ofx_kit/transaction_collection.rb
|
|
132
152
|
- lib/ofx_kit/version.rb
|
|
133
153
|
homepage: https://github.com/lucasgeron/ofx_kit
|
|
134
154
|
licenses:
|
|
135
155
|
- MIT
|
|
136
156
|
metadata:
|
|
157
|
+
homepage_uri: https://github.com/lucasgeron/ofx_kit
|
|
137
158
|
source_code_uri: https://github.com/lucasgeron/ofx_kit
|
|
159
|
+
changelog_uri: https://lucasgeron.github.io/ofx_kit/CHANGELOG_md
|
|
160
|
+
documentation_uri: https://lucasgeron.github.io/ofx_kit/
|
|
138
161
|
rubygems_mfa_required: 'true'
|
|
139
162
|
rdoc_options: []
|
|
140
163
|
require_paths:
|
|
@@ -143,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
143
166
|
requirements:
|
|
144
167
|
- - ">="
|
|
145
168
|
- !ruby/object:Gem::Version
|
|
146
|
-
version: '3.
|
|
169
|
+
version: '3.2'
|
|
147
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
171
|
requirements:
|
|
149
172
|
- - ">="
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OFX
|
|
4
|
-
# Represents a single financial transaction parsed from an OFX statement.
|
|
5
|
-
class Transaction < Base::Entity
|
|
6
|
-
attr_accessor :fit_id, :type, :posted_at, :occurred_at,
|
|
7
|
-
:amount, :amount_cents,
|
|
8
|
-
:name, :memo, :payee,
|
|
9
|
-
:check_number, :ref_number, :sic
|
|
10
|
-
|
|
11
|
-
wired_by_builder :statement, :account
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OFX
|
|
4
|
-
# An +Enumerable+ collection of {Transaction} objects parsed from an OFX statement.
|
|
5
|
-
# Provides convenience filters for credits and debits.
|
|
6
|
-
class TransactionCollection
|
|
7
|
-
include Enumerable
|
|
8
|
-
|
|
9
|
-
# Placeholder overridden per-instance by {Base::Builder#wire} at build time.
|
|
10
|
-
def statement = nil
|
|
11
|
-
|
|
12
|
-
# @param transactions [Array<Transaction>] the list of transactions
|
|
13
|
-
def initialize(transactions)
|
|
14
|
-
@transactions = transactions
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Iterates over each transaction.
|
|
18
|
-
# @yieldparam transaction [Transaction]
|
|
19
|
-
def each(&)
|
|
20
|
-
@transactions.each(&)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# @return [Integer] number of transactions in the collection
|
|
24
|
-
def length
|
|
25
|
-
@transactions.length
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# @return [TransactionCollection] a new collection containing only positive-amount transactions
|
|
29
|
-
def credits
|
|
30
|
-
sub = self.class.new(select { |t| t.amount.positive? })
|
|
31
|
-
# Propagate statement wiring so inferred_currency resolves to the correct
|
|
32
|
-
# account currency even when this sub-collection has no transactions.
|
|
33
|
-
if (stmt = statement)
|
|
34
|
-
sub.define_singleton_method(:statement) { stmt }
|
|
35
|
-
end
|
|
36
|
-
sub
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @return [TransactionCollection] a new collection containing only negative-amount transactions
|
|
40
|
-
def debits
|
|
41
|
-
sub = self.class.new(select { |t| t.amount.negative? })
|
|
42
|
-
# Same as credits — statement is the authoritative source of currency.
|
|
43
|
-
if (stmt = statement)
|
|
44
|
-
sub.define_singleton_method(:statement) { stmt }
|
|
45
|
-
end
|
|
46
|
-
sub
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# @return [Money] sum of all positive transaction amounts
|
|
50
|
-
def total_credits
|
|
51
|
-
sum_amounts(credits)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# @return [Money] sum of all negative transaction amounts
|
|
55
|
-
def total_debits
|
|
56
|
-
sum_amounts(debits)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# @return [Money] net amount (credits + debits)
|
|
60
|
-
# @note This is NOT the account balance. It reflects only the transactions present in
|
|
61
|
-
# the OFX file and ignores any accumulated prior balance (e.g. opening cash balance
|
|
62
|
-
# or unpaid invoice from a previous period). Use {Balance} for the actual account balance.
|
|
63
|
-
def net
|
|
64
|
-
total_credits + total_debits
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# @return [Array<Transaction>] a duplicate of the internal transactions array
|
|
68
|
-
def to_a
|
|
69
|
-
@transactions.dup
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# @param other [TransactionCollection] collection to compare against
|
|
73
|
-
# @return [Boolean]
|
|
74
|
-
def ==(other)
|
|
75
|
-
@transactions == other.to_a
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private
|
|
79
|
-
|
|
80
|
-
def currency
|
|
81
|
-
statement&.account&.currency
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def inferred_currency
|
|
85
|
-
currency || OFX.config.default_currency
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def sum_amounts(collection)
|
|
89
|
-
return Money.new(0, inferred_currency) if collection.none?
|
|
90
|
-
|
|
91
|
-
collection.map(&:amount).inject(:+)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
data/lib/ofx_kit/errors.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OFX
|
|
4
|
-
# Base error class for all OFX-related exceptions.
|
|
5
|
-
class Error < StandardError; end
|
|
6
|
-
|
|
7
|
-
# Raised when the OFX file cannot be parsed.
|
|
8
|
-
class ParseError < Error; end
|
|
9
|
-
|
|
10
|
-
# Raised when the OFX file header is malformed or missing.
|
|
11
|
-
class InvalidHeaderError < ParseError; end
|
|
12
|
-
|
|
13
|
-
# Raised when the OFX file body cannot be parsed into a valid document.
|
|
14
|
-
class InvalidBodyError < ParseError; end
|
|
15
|
-
|
|
16
|
-
# Raised when the OFX version declared in the file is not supported.
|
|
17
|
-
class UnsupportedVersionError < Error
|
|
18
|
-
# @return [String] the unsupported version string found in the file
|
|
19
|
-
attr_reader :version
|
|
20
|
-
|
|
21
|
-
# @param version [String] the unsupported OFX version string
|
|
22
|
-
def initialize(version)
|
|
23
|
-
@version = version
|
|
24
|
-
super("Unsupported OFX version: #{version}")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Raised when a character encoding error occurs while reading the OFX file.
|
|
29
|
-
class EncodingError < Error; end
|
|
30
|
-
|
|
31
|
-
# Raised when the library configuration is invalid or inconsistent.
|
|
32
|
-
class ConfigurationError < Error; end
|
|
33
|
-
|
|
34
|
-
# Raised when an operation requires a single statement but multiple were found.
|
|
35
|
-
class MultipleStatementsError < Error; end
|
|
36
|
-
end
|
|
File without changes
|