norma43_parser 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/CHANGELOG.md +11 -2
- data/Gemfile.lock +1 -19
- data/lib/norma43/models/account.rb +51 -19
- data/lib/norma43/models/additional_currency.rb +13 -7
- data/lib/norma43/models/additional_item.rb +11 -6
- data/lib/norma43/models/document.rb +30 -11
- data/lib/norma43/models/mixins/attributes_assignment.rb +33 -0
- data/lib/norma43/models/transaction.rb +41 -15
- data/lib/norma43/models.rb +0 -2
- data/lib/norma43/version.rb +1 -1
- data/norma43_parser.gemspec +0 -1
- data/spec/norma43/line_processors/account_end_spec.rb +1 -4
- data/spec/norma43/line_processors/account_start_spec.rb +3 -3
- data/spec/norma43/line_processors/additional_currency_spec.rb +3 -3
- data/spec/norma43/line_processors/{additional_items_spec.rb → additional_item_spec.rb} +3 -3
- data/spec/norma43/line_processors/document_end_spec.rb +3 -6
- data/spec/norma43/line_processors/document_start_spec.rb +3 -3
- data/spec/norma43/line_processors/transaction_spec.rb +3 -3
- data/spec/norma43/models/account_spec.rb +39 -5
- data/spec/norma43/models/document_spec.rb +35 -0
- data/spec/norma43/models/transaction_spec.rb +25 -0
- data/spec/norma43_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/support/shared_examples_for_models.rb +61 -0
- metadata +12 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70aa150ed65a01abcb09b13665b3969c94e3715d40ee499a5d4e33332820f046
|
4
|
+
data.tar.gz: 86fb452b32c9b3cdd7732334ecbdc2e49bb4b051947789f0307a9e3314f3cd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2edf9e870901979eef621ec3e70b62257ee3f762d778940c5a75c5ccde57e466f1fde49d1a9d68074381358755e569c326a1f404a1ea4b8619d7c3d27d7315ef
|
7
|
+
data.tar.gz: '085513b1e92b678eb0a7f5eaefb10a09728056516ef011d93cda4e299de39998e30a95cf5c6e7af25e9c5c9657deeed1b7f4aa29a8cc907bc95bef87d81fd739'
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
## [4.
|
1
|
+
## [4.1.0](https://github.com/sequra/norma43_parser/compare/v4.0.0...v4.1.0) (2024-06-20)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
|
5
|
+
* Remove virtus dependency ([#35](https://github.com/sequra/norma43_parser/issues/35))
|
6
|
+
|
7
|
+
* Soft-deprecate `Norma43::Models::Document#transaction_date`, use transaction_date in transactions instead
|
2
8
|
|
3
9
|
|
10
|
+
## [4.0.0](https://github.com/sequra/norma43_parser/compare/3.0.0...v4.0.0) (2024-06-18)
|
11
|
+
|
4
12
|
### ⚠ BREAKING CHANGES
|
5
13
|
|
6
14
|
* Drop Ruby support below 3
|
@@ -16,19 +24,20 @@
|
|
16
24
|
|
17
25
|
- Drop Ruby support below 2.6.
|
18
26
|
|
27
|
+
|
19
28
|
## v2.1.1 (2020-03-13)
|
20
29
|
|
21
30
|
### Enhancements
|
22
31
|
|
23
32
|
- Update rake requirement from ~> 10.0 to ~> 13.0 (#6)
|
24
33
|
|
34
|
+
|
25
35
|
## v2.0.0 (2019-10-17)
|
26
36
|
|
27
37
|
### Breaking Changes
|
28
38
|
|
29
39
|
- Drop Ruby support below 2.4.
|
30
40
|
|
31
|
-
|
32
41
|
### Enhancements
|
33
42
|
|
34
43
|
- Clean up dependencies
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
norma43_parser (4.
|
5
|
-
virtus (~> 1.0)
|
4
|
+
norma43_parser (4.1.0)
|
6
5
|
zeitwerk (~> 2.0)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
10
|
ast (2.4.2)
|
12
|
-
axiom-types (0.1.1)
|
13
|
-
descendants_tracker (~> 0.0.4)
|
14
|
-
ice_nine (~> 0.11.0)
|
15
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
16
|
-
coercible (1.0.0)
|
17
|
-
descendants_tracker (~> 0.0.1)
|
18
|
-
descendants_tracker (0.0.4)
|
19
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
20
11
|
diff-lcs (1.5.1)
|
21
|
-
equalizer (0.0.11)
|
22
|
-
ice_nine (0.11.2)
|
23
12
|
json (2.7.2)
|
24
13
|
json (2.7.2-java)
|
25
14
|
language_server-protocol (3.17.0.3)
|
@@ -66,14 +55,7 @@ GEM
|
|
66
55
|
ruby-progressbar (1.13.0)
|
67
56
|
strscan (3.1.0)
|
68
57
|
strscan (3.1.0-java)
|
69
|
-
thread_safe (0.3.6)
|
70
|
-
thread_safe (0.3.6-java)
|
71
58
|
unicode-display_width (2.5.0)
|
72
|
-
virtus (1.0.5)
|
73
|
-
axiom-types (~> 0.1)
|
74
|
-
coercible (~> 1.0)
|
75
|
-
descendants_tracker (~> 0.0, >= 0.0.3)
|
76
|
-
equalizer (~> 0.0, >= 0.0.9)
|
77
59
|
zeitwerk (2.6.15)
|
78
60
|
|
79
61
|
PLATFORMS
|
@@ -1,30 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus"
|
4
|
-
|
5
3
|
module Norma43
|
6
4
|
module Models
|
7
5
|
class Account
|
8
|
-
include
|
6
|
+
include Mixins::AttributesAssignment
|
7
|
+
|
8
|
+
attr_accessor :bank_code,
|
9
|
+
:branch_code,
|
10
|
+
:account_number,
|
11
|
+
:start_date,
|
12
|
+
:end_date,
|
13
|
+
:balance_code,
|
14
|
+
:balance_amount,
|
15
|
+
:currency_code,
|
16
|
+
:information_mode_code,
|
17
|
+
:abbreviated_name,
|
18
|
+
:debit_entries,
|
19
|
+
:debit_amount,
|
20
|
+
:credit_entries,
|
21
|
+
:credit_amount,
|
22
|
+
:transactions
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def initialize(attributes = EMPTY_ATTRIBUTES)
|
25
|
+
@bank_code,
|
26
|
+
@branch_code,
|
27
|
+
@account_number,
|
28
|
+
@start_date,
|
29
|
+
@end_date,
|
30
|
+
@balance_code,
|
31
|
+
@balance_amount,
|
32
|
+
@currency_code,
|
33
|
+
@information_mode_code,
|
34
|
+
@abbreviated_name,
|
35
|
+
@debit_entries,
|
36
|
+
@debit_amount,
|
37
|
+
@credit_entries,
|
38
|
+
@credit_amount,
|
39
|
+
transactions = Hash(attributes).values_at(
|
40
|
+
:bank_code,
|
41
|
+
:branch_code,
|
42
|
+
:account_number,
|
43
|
+
:start_date,
|
44
|
+
:end_date,
|
45
|
+
:balance_code,
|
46
|
+
:balance_amount,
|
47
|
+
:currency_code,
|
48
|
+
:information_mode_code,
|
49
|
+
:abbreviated_name,
|
50
|
+
:debit_entries,
|
51
|
+
:debit_amount,
|
52
|
+
:credit_entries,
|
53
|
+
:credit_amount,
|
54
|
+
:transactions)
|
55
|
+
@transactions = Array(transactions).map { |attrs| Transaction.new(attrs) }
|
56
|
+
end
|
25
57
|
|
26
58
|
def iban
|
27
|
-
|
59
|
+
SpanishIban.from_account(self)
|
28
60
|
end
|
29
61
|
end
|
30
62
|
end
|
@@ -1,16 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus"
|
4
|
-
|
5
3
|
module Norma43
|
6
4
|
module Models
|
7
5
|
class AdditionalCurrency
|
8
|
-
include
|
6
|
+
include Mixins::AttributesAssignment
|
7
|
+
|
8
|
+
attr_accessor :data_code, :currency_code, :amount, :free
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize(attributes = EMPTY_ATTRIBUTES)
|
11
|
+
@data_code,
|
12
|
+
@currency_code,
|
13
|
+
@amount,
|
14
|
+
@free = Hash(attributes).values_at(
|
15
|
+
:data_code,
|
16
|
+
:currency_code,
|
17
|
+
:amount,
|
18
|
+
:free)
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
@@ -1,15 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus"
|
4
|
-
|
5
3
|
module Norma43
|
6
4
|
module Models
|
7
5
|
class AdditionalItem
|
8
|
-
include
|
6
|
+
include Mixins::AttributesAssignment
|
7
|
+
|
8
|
+
attr_accessor :data_code, :item_1, :item_2
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(attributes = EMPTY_ATTRIBUTES)
|
11
|
+
@data_code,
|
12
|
+
@item_1,
|
13
|
+
@item_2 = Hash(attributes).values_at(
|
14
|
+
:data_code,
|
15
|
+
:item_1,
|
16
|
+
:item_2)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
@@ -1,22 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus"
|
4
|
-
|
5
3
|
module Norma43
|
6
4
|
module Models
|
7
5
|
class Document
|
8
|
-
include
|
6
|
+
include Mixins::AttributesAssignment
|
7
|
+
|
8
|
+
attr_accessor :id, :created_at, :delivery_number, :file_type, :name, :number_of_lines, :accounts
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def initialize(attributes = EMPTY_ATTRIBUTES)
|
11
|
+
@id,
|
12
|
+
@created_at,
|
13
|
+
@delivery_number,
|
14
|
+
@file_type,
|
15
|
+
@name,
|
16
|
+
@number_of_lines,
|
17
|
+
accounts = Hash(attributes).values_at(
|
18
|
+
:id,
|
19
|
+
:created_at,
|
20
|
+
:delivery_number,
|
21
|
+
:file_type,
|
22
|
+
:name,
|
23
|
+
:number_of_lines,
|
24
|
+
:accounts)
|
25
|
+
@accounts = Array(accounts).map { |account| Account.new(account) }
|
26
|
+
end
|
17
27
|
|
28
|
+
# @deprecated Please ask each transaction inside accounts for their transaction_date instead
|
18
29
|
def transaction_date
|
19
|
-
accounts
|
30
|
+
warn "[DEPRECATION] `transaction_date` is deprecated, use `#transaction_date` from transactions in `#accounts` instead"
|
31
|
+
date = nil
|
32
|
+
|
33
|
+
accounts.flat_map(&:transactions).each { |transaction|
|
34
|
+
date = transaction&.transaction_date
|
35
|
+
break unless date.nil?
|
36
|
+
}
|
37
|
+
|
38
|
+
date
|
20
39
|
end
|
21
40
|
end
|
22
41
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Norma43
|
4
|
+
module Models
|
5
|
+
module Mixins
|
6
|
+
module AttributesAssignment
|
7
|
+
EMPTY_ATTRIBUTES = {}.freeze
|
8
|
+
|
9
|
+
def attributes=(new_attributes)
|
10
|
+
Hash(new_attributes).each do |attr_name, attr_value|
|
11
|
+
attr_writer_method_name = "#{attr_name}=".to_sym
|
12
|
+
next unless public_methods(false).include?(attr_writer_method_name)
|
13
|
+
|
14
|
+
public_send(attr_writer_method_name, attr_value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def attributes
|
19
|
+
instance_variables.map { |ivar_name|
|
20
|
+
attr_reader_method_name = ivar_name.to_s.delete_prefix("@").to_sym
|
21
|
+
next unless public_methods(false).include?(attr_reader_method_name)
|
22
|
+
|
23
|
+
attr_value = public_send(attr_reader_method_name)
|
24
|
+
|
25
|
+
[attr_reader_method_name, attr_value]
|
26
|
+
}.compact.to_h
|
27
|
+
end
|
28
|
+
alias_method :to_hash, :attributes # Implicit coercion for `Hash(model)`
|
29
|
+
alias_method :to_h, :attributes # Explicit coercion
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,24 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus"
|
4
|
-
|
5
3
|
module Norma43
|
6
4
|
module Models
|
7
5
|
class Transaction
|
8
|
-
include
|
6
|
+
include Mixins::AttributesAssignment
|
7
|
+
|
8
|
+
attr_accessor :origin_branch_code,
|
9
|
+
:transaction_date,
|
10
|
+
:value_date,
|
11
|
+
:shared_item,
|
12
|
+
:own_item,
|
13
|
+
:amount_code,
|
14
|
+
:amount,
|
15
|
+
:document_number,
|
16
|
+
:reference_1,
|
17
|
+
:reference_2,
|
18
|
+
:additional_items,
|
19
|
+
:additional_currency
|
20
|
+
|
21
|
+
def initialize(attributes = EMPTY_ATTRIBUTES)
|
22
|
+
@origin_branch_code,
|
23
|
+
@transaction_date,
|
24
|
+
@value_date,
|
25
|
+
@shared_item,
|
26
|
+
@own_item,
|
27
|
+
@amount_code,
|
28
|
+
@amount,
|
29
|
+
@document_number,
|
30
|
+
@reference_1,
|
31
|
+
@reference_2,
|
32
|
+
additional_items,
|
33
|
+
additional_currency = Hash(attributes).values_at(
|
34
|
+
:origin_branch_code,
|
35
|
+
:transaction_date,
|
36
|
+
:value_date,
|
37
|
+
:shared_item,
|
38
|
+
:own_item,
|
39
|
+
:amount_code,
|
40
|
+
:amount,
|
41
|
+
:document_number,
|
42
|
+
:reference_1,
|
43
|
+
:reference_2)
|
44
|
+
@additional_items = Array(additional_items).map { |attrs| AdditionalItem.new(attrs) }
|
45
|
+
@additional_currency = AdditionalCurrency.new(additional_currency) if additional_currency
|
46
|
+
end
|
9
47
|
|
10
|
-
attribute :origin_branch_code
|
11
|
-
attribute :transaction_date
|
12
|
-
attribute :value_date
|
13
|
-
attribute :shared_item
|
14
|
-
attribute :own_item
|
15
|
-
attribute :amount_code
|
16
|
-
attribute :amount
|
17
|
-
attribute :document_number
|
18
|
-
attribute :reference_1
|
19
|
-
attribute :reference_2
|
20
|
-
attribute :additional_items, Array[AdditionalItem]
|
21
|
-
attribute :additional_currency, AdditionalCurrency
|
22
48
|
def debit?; self.amount_code == DEBIT_CODE end
|
23
49
|
end
|
24
50
|
end
|
data/lib/norma43/models.rb
CHANGED
data/lib/norma43/version.rb
CHANGED
data/norma43_parser.gemspec
CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "virtus", "~> 1.0"
|
23
22
|
spec.add_runtime_dependency "zeitwerk", "~> 2.0"
|
24
23
|
|
25
24
|
spec.add_development_dependency "rake", "~> 13.0"
|
@@ -3,10 +3,7 @@
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
5
|
RSpec.describe AccountEnd do
|
6
|
-
let
|
7
|
-
double "Line", attributes: {}
|
8
|
-
end
|
9
|
-
|
6
|
+
let(:line) { instance_double(LineParsers::AccountEnd, attributes: {}) }
|
10
7
|
let(:account) { Norma43::Models::Account.new }
|
11
8
|
let(:contexts) { Norma43::Utils::Contexts.new(
|
12
9
|
[
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe AccountStart do
|
6
|
+
let(:line) { instance_double(LineParsers::AccountStart, attributes: {}) }
|
7
7
|
let(:document) { Norma43::Models::Document.new }
|
8
8
|
let(:contexts) { Norma43::Utils::Contexts.new }
|
9
9
|
|
@@ -20,7 +20,7 @@ module Norma43
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context "when AccountStart is called" do
|
23
|
-
let(:fake_account) {
|
23
|
+
let(:fake_account) { instance_double(Norma43::Models::Account) }
|
24
24
|
before do
|
25
25
|
allow(Norma43::Models::Account).to receive(:new) { fake_account }
|
26
26
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe AdditionalCurrency do
|
6
|
+
let(:line) { instance_double(LineParsers::AdditionalCurrency, attributes: {}) }
|
7
7
|
let(:transaction) { Norma43::Models::Transaction.new }
|
8
8
|
let(:contexts) { Norma43::Utils::Contexts.new(
|
9
9
|
[
|
@@ -22,7 +22,7 @@ module Norma43
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when AdditionalCurrency is called" do
|
25
|
-
let(:fake_additional_currency) {
|
25
|
+
let(:fake_additional_currency) { instance_double(Models::AdditionalCurrency) }
|
26
26
|
before do
|
27
27
|
allow(Models::AdditionalCurrency).to receive(:new) { fake_additional_currency }
|
28
28
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe AdditionalItem do
|
6
|
+
let(:line) { instance_double(LineParsers::AdditionalItem, attributes: {}) }
|
7
7
|
let(:transaction) { Norma43::Models::Transaction.new }
|
8
8
|
let(:contexts) { Norma43::Utils::Contexts.new(
|
9
9
|
[
|
@@ -22,7 +22,7 @@ module Norma43
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when AdditionalItem is called" do
|
25
|
-
let(:fake_additional_item) {
|
25
|
+
let(:fake_additional_item) { instance_double(Models::AdditionalItem) }
|
26
26
|
before do
|
27
27
|
allow(Models::AdditionalItem).to receive(:new) { fake_additional_item }
|
28
28
|
end
|
@@ -2,15 +2,12 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:line) { double "Line", record_number: 35 }
|
5
|
+
RSpec.describe DocumentEnd do
|
6
|
+
let(:line) { instance_double(LineParsers::DocumentEnd, record_number: 35) }
|
10
7
|
|
11
8
|
it "moves to the nearest document context" do
|
12
9
|
document = Norma43::Models::Document.new
|
13
|
-
contexts = Norma43::Utils::Contexts.new [
|
10
|
+
contexts = Norma43::Utils::Contexts.new [anything, document, anything, anything]
|
14
11
|
|
15
12
|
DocumentEnd.call line, contexts
|
16
13
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
let
|
5
|
+
RSpec.describe DocumentStart do
|
6
|
+
let(:line) { instance_double(LineParsers::DocumentStart, attributes: {}) }
|
7
7
|
|
8
8
|
it "instantiates a new document with the line attributes" do
|
9
9
|
allow(Models::Document).to receive :new
|
@@ -14,7 +14,7 @@ module Norma43
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "sets the document as the current context" do
|
17
|
-
fake_document =
|
17
|
+
fake_document = instance_double(Models::Document)
|
18
18
|
allow(Models::Document).to receive(:new) { fake_document }
|
19
19
|
|
20
20
|
contexts = DocumentStart.call line, Norma43::Utils::Contexts.new
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe Transaction do
|
6
|
+
let(:line) { instance_double(LineParsers::Transaction, attributes: {}) }
|
7
7
|
let(:account) { Norma43::Models::Account.new }
|
8
8
|
let(:contexts) { Norma43::Utils::Contexts.new(
|
9
9
|
[
|
@@ -22,7 +22,7 @@ module Norma43
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when Transaction is called" do
|
25
|
-
let(:fake_transaction) {
|
25
|
+
let(:fake_transaction) { instance_double(Models::Transaction) }
|
26
26
|
before do
|
27
27
|
allow(Models::Transaction).to receive(:new) { fake_transaction }
|
28
28
|
end
|
@@ -3,17 +3,51 @@
|
|
3
3
|
module Norma43
|
4
4
|
module Models
|
5
5
|
RSpec.describe Account do
|
6
|
+
it_behaves_like "a model"
|
7
|
+
|
6
8
|
describe "#iban" do
|
7
|
-
it { is_expected.to respond_to
|
9
|
+
it { is_expected.to respond_to(:iban) }
|
8
10
|
|
9
11
|
context "with the example in the documentation" do
|
10
|
-
it "
|
12
|
+
it "returns the correct IBAN string" do
|
11
13
|
account = subject
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
account.account_number = 1234567
|
15
|
+
account.bank_code = 81
|
16
|
+
account.branch_code = 54
|
17
|
+
|
18
|
+
expect(account.iban).to eq("ES5400810054180001234567")
|
15
19
|
end
|
16
20
|
end
|
21
|
+
|
22
|
+
context "with missing bank data" do
|
23
|
+
subject { described_class.new.iban }
|
24
|
+
it { is_expected.to be_nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with missing bank code" do
|
28
|
+
subject { described_class.new(bank_code: nil, branch_code: 1234, account_number: 1234).iban }
|
29
|
+
it { is_expected.to be_nil }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with missing branch code" do
|
33
|
+
subject { described_class.new(bank_code: 1234, branch_code: nil, account_number: 1234).iban }
|
34
|
+
it { is_expected.to be_nil }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with missing account number" do
|
38
|
+
subject { described_class.new(bank_code: 1234, branch_code: 1234, account_number: nil).iban }
|
39
|
+
it { is_expected.to be_nil }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with negative account number" do
|
43
|
+
subject { described_class.new(bank_code: 1234, branch_code: 1234, account_number: -1234).iban }
|
44
|
+
it { is_expected.to be_nil }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with an account number which is too large" do
|
48
|
+
subject { described_class.new(bank_code: 1234, branch_code: 1234, account_number: 1*10**10).iban }
|
49
|
+
it { is_expected.to be_nil }
|
50
|
+
end
|
17
51
|
end
|
18
52
|
end
|
19
53
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Norma43
|
4
|
+
module Models
|
5
|
+
RSpec.describe Document do
|
6
|
+
it_behaves_like "a model"
|
7
|
+
|
8
|
+
describe "#transaction_date" do
|
9
|
+
it { is_expected.to respond_to(:transaction_date) }
|
10
|
+
|
11
|
+
context "when there are no accounts" do
|
12
|
+
subject(:document) { described_class.new({ accounts: [] }) }
|
13
|
+
|
14
|
+
it { expect(document.transaction_date).to be_nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when there are accounts" do
|
18
|
+
subject(:document) { described_class.new({ accounts: [account] }) }
|
19
|
+
|
20
|
+
let(:account) {
|
21
|
+
Account.new(transactions: [
|
22
|
+
nil,
|
23
|
+
Transaction.new(transaction_date: nil),
|
24
|
+
Transaction.new(transaction_date: Date.parse("2024-01-23")),
|
25
|
+
])
|
26
|
+
}
|
27
|
+
|
28
|
+
it "returns the date of the first account with a transaction date" do
|
29
|
+
expect(document.transaction_date).to eq(Date.parse("2024-01-23"))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Norma43
|
4
|
+
module Models
|
5
|
+
RSpec.describe Transaction do
|
6
|
+
it_behaves_like "a model"
|
7
|
+
|
8
|
+
describe "#debit?" do
|
9
|
+
it { is_expected.to respond_to(:debit?) }
|
10
|
+
|
11
|
+
context "when amount code is code for debits" do
|
12
|
+
subject(:transaction) { described_class.new(amount_code: 1) }
|
13
|
+
|
14
|
+
it { expect(transaction.debit?).to be_truthy }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when amount code is code for credits" do
|
18
|
+
subject(:transaction) { described_class.new(amount_code: 2) }
|
19
|
+
|
20
|
+
it { expect(transaction.debit?).to be_falsey }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/norma43_spec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe Norma43 do
|
|
6
6
|
describe "#parse" do
|
7
7
|
it "returns the parser results" do
|
8
8
|
text = "some total-in text"
|
9
|
-
parser =
|
9
|
+
parser = instance_double(Norma43::Parser, result: "result")
|
10
10
|
expect(Norma43::Parser).to receive(:new).with(text) { parser }
|
11
11
|
|
12
12
|
expect(Norma43.parse(text)).to eq "result"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "norma43"
|
4
|
+
|
3
5
|
RSpec.configure do |config|
|
4
6
|
config.order = :random
|
5
7
|
Kernel.srand config.seed
|
@@ -11,6 +13,7 @@ RSpec.configure do |config|
|
|
11
13
|
config.mock_with :rspec do |mocks|
|
12
14
|
mocks.syntax = :expect
|
13
15
|
mocks.verify_partial_doubles = true
|
16
|
+
mocks.verify_doubled_constant_names = true
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples "a model" do
|
4
|
+
it { is_expected.to respond_to(:attributes) }
|
5
|
+
it { is_expected.to respond_to(:attributes=) }
|
6
|
+
it { is_expected.to respond_to(:to_h) }
|
7
|
+
it { is_expected.to respond_to(:to_hash) }
|
8
|
+
|
9
|
+
describe "#new" do
|
10
|
+
subject(:model) { described_class.new(attributes) }
|
11
|
+
|
12
|
+
context "when instantiated with an empty hash" do
|
13
|
+
let(:attributes) { {} }
|
14
|
+
|
15
|
+
it "accepts it without failing" do
|
16
|
+
expect { model }.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#attributes" do
|
22
|
+
subject { described_class.new.attributes }
|
23
|
+
|
24
|
+
it { is_expected.not_to be_empty }
|
25
|
+
it { is_expected.to respond_to(:each_pair) }
|
26
|
+
it { is_expected.to respond_to(:to_h) }
|
27
|
+
it { is_expected.to respond_to(:to_hash) }
|
28
|
+
it { is_expected.to respond_to(:keys) }
|
29
|
+
|
30
|
+
describe "#attributes.keys" do
|
31
|
+
subject { super().keys }
|
32
|
+
|
33
|
+
it { is_expected.not_to be_empty }
|
34
|
+
it { is_expected.to all(be_a(Symbol)) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#attributes=" do
|
39
|
+
subject { described_class.new.attributes=(attributes) }
|
40
|
+
|
41
|
+
context "when passed an empty hash" do
|
42
|
+
let(:attributes) { {} }
|
43
|
+
|
44
|
+
it "accepts it without failing" do
|
45
|
+
expect { subject }.not_to raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when passed a hash with unknown attribute names" do
|
50
|
+
let(:attributes) { { potato: nil } }
|
51
|
+
|
52
|
+
it "accepts it without failing" do
|
53
|
+
expect { subject }.not_to raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not set any new method" do
|
57
|
+
expect { subject.potato }.to raise_error(NoMethodError, /undefined method.+potato/i)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norma43_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sequra engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: virtus
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: zeitwerk
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +63,7 @@ files:
|
|
77
63
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
78
64
|
- ".github/workflows/ci.yml"
|
79
65
|
- ".github/workflows/release.yml"
|
66
|
+
- ".rspec"
|
80
67
|
- ".rubocop.yml"
|
81
68
|
- CHANGELOG.md
|
82
69
|
- Gemfile
|
@@ -104,6 +91,7 @@ files:
|
|
104
91
|
- lib/norma43/models/additional_currency.rb
|
105
92
|
- lib/norma43/models/additional_item.rb
|
106
93
|
- lib/norma43/models/document.rb
|
94
|
+
- lib/norma43/models/mixins/attributes_assignment.rb
|
107
95
|
- lib/norma43/models/transaction.rb
|
108
96
|
- lib/norma43/parser.rb
|
109
97
|
- lib/norma43/utils/contexts.rb
|
@@ -123,15 +111,18 @@ files:
|
|
123
111
|
- spec/norma43/line_processors/account_end_spec.rb
|
124
112
|
- spec/norma43/line_processors/account_start_spec.rb
|
125
113
|
- spec/norma43/line_processors/additional_currency_spec.rb
|
126
|
-
- spec/norma43/line_processors/
|
114
|
+
- spec/norma43/line_processors/additional_item_spec.rb
|
127
115
|
- spec/norma43/line_processors/document_end_spec.rb
|
128
116
|
- spec/norma43/line_processors/document_start_spec.rb
|
129
117
|
- spec/norma43/line_processors/transaction_spec.rb
|
130
118
|
- spec/norma43/models/account/spanish_iban_spec.rb
|
131
119
|
- spec/norma43/models/account_spec.rb
|
120
|
+
- spec/norma43/models/document_spec.rb
|
121
|
+
- spec/norma43/models/transaction_spec.rb
|
132
122
|
- spec/norma43/parser_spec.rb
|
133
123
|
- spec/norma43_spec.rb
|
134
124
|
- spec/spec_helper.rb
|
125
|
+
- spec/support/shared_examples_for_models.rb
|
135
126
|
- spec/support/shared_examples_for_values_line_parsers.rb
|
136
127
|
homepage: https://github.com/sequra/norma43_parser
|
137
128
|
licenses:
|
@@ -169,13 +160,16 @@ test_files:
|
|
169
160
|
- spec/norma43/line_processors/account_end_spec.rb
|
170
161
|
- spec/norma43/line_processors/account_start_spec.rb
|
171
162
|
- spec/norma43/line_processors/additional_currency_spec.rb
|
172
|
-
- spec/norma43/line_processors/
|
163
|
+
- spec/norma43/line_processors/additional_item_spec.rb
|
173
164
|
- spec/norma43/line_processors/document_end_spec.rb
|
174
165
|
- spec/norma43/line_processors/document_start_spec.rb
|
175
166
|
- spec/norma43/line_processors/transaction_spec.rb
|
176
167
|
- spec/norma43/models/account/spanish_iban_spec.rb
|
177
168
|
- spec/norma43/models/account_spec.rb
|
169
|
+
- spec/norma43/models/document_spec.rb
|
170
|
+
- spec/norma43/models/transaction_spec.rb
|
178
171
|
- spec/norma43/parser_spec.rb
|
179
172
|
- spec/norma43_spec.rb
|
180
173
|
- spec/spec_helper.rb
|
174
|
+
- spec/support/shared_examples_for_models.rb
|
181
175
|
- spec/support/shared_examples_for_values_line_parsers.rb
|