norma43_parser 3.1.0 → 4.0.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/CHANGELOG.md +0 -7
- data/Gemfile.lock +19 -1
- data/lib/norma43/models/account.rb +19 -51
- data/lib/norma43/models/additional_currency.rb +7 -13
- data/lib/norma43/models/additional_item.rb +6 -11
- data/lib/norma43/models/document.rb +11 -30
- data/lib/norma43/models/transaction.rb +15 -41
- data/lib/norma43/models.rb +2 -0
- data/lib/norma43/version.rb +1 -1
- data/norma43_parser.gemspec +1 -0
- data/spec/norma43/line_processors/account_end_spec.rb +4 -1
- 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_item_spec.rb → additional_items_spec.rb} +3 -3
- data/spec/norma43/line_processors/document_end_spec.rb +6 -3
- 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 +5 -39
- data/spec/norma43_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- metadata +17 -11
- data/.rspec +0 -1
- data/lib/norma43/models/mixins/attributes_assignment.rb +0 -33
- data/spec/norma43/models/document_spec.rb +0 -35
- data/spec/norma43/models/transaction_spec.rb +0 -25
- data/spec/support/shared_examples_for_models.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0449ec18860a4308816374b89703797ec359a8032b15a3f3fb3e4a8749dbdc44'
|
4
|
+
data.tar.gz: 0d0438fb23ba70c0b5c3ce107e7ac6e71dd5007ceb2fe64887aaf0d61c46cf60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd5abd1c1b2893eb6fcb8c2025d659c1c5876198d68d624e19e18ac1975aecb48c557f7a27070c690f0090028d630a6d2ece30daf7daad70eda3993a736e56fe
|
7
|
+
data.tar.gz: 5431b59a68a1f3ce474e31aa44735ad9a6c1863deb20e157375e8b81938192d99e6184f587b6eadefffd992bf6fd5398acea5e261d2100f70be4bd59d4b019f3
|
data/CHANGELOG.md
CHANGED
@@ -10,13 +10,6 @@
|
|
10
10
|
* Get IBANs from account instances ([#15](https://github.com/sequra/norma43_parser/issues/15)) ([c69d162](https://github.com/sequra/norma43_parser/commit/c69d162361b188f2b2d904b1958e3108be9a3939))
|
11
11
|
|
12
12
|
|
13
|
-
## [3.1.0](https://github.com/sequra/norma43_parser/compare/3.0.0...v3.1.0) (2024-06-19)
|
14
|
-
|
15
|
-
|
16
|
-
### Features
|
17
|
-
|
18
|
-
* get IBANs from account instances ([#15](https://github.com/sequra/norma43_parser/issues/15)) ([3a5dd36](https://github.com/sequra/norma43_parser/commit/3a5dd366a934525e421d3cbcaceabb88a285fb6d))
|
19
|
-
|
20
13
|
## v3.0.0 (2021-12-15)
|
21
14
|
|
22
15
|
### Breaking Changes
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
norma43_parser (
|
4
|
+
norma43_parser (4.0.0)
|
5
|
+
virtus (~> 1.0)
|
5
6
|
zeitwerk (~> 2.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
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)
|
11
20
|
diff-lcs (1.5.1)
|
21
|
+
equalizer (0.0.11)
|
22
|
+
ice_nine (0.11.2)
|
12
23
|
json (2.7.2)
|
13
24
|
json (2.7.2-java)
|
14
25
|
language_server-protocol (3.17.0.3)
|
@@ -55,7 +66,14 @@ GEM
|
|
55
66
|
ruby-progressbar (1.13.0)
|
56
67
|
strscan (3.1.0)
|
57
68
|
strscan (3.1.0-java)
|
69
|
+
thread_safe (0.3.6)
|
70
|
+
thread_safe (0.3.6-java)
|
58
71
|
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)
|
59
77
|
zeitwerk (2.6.15)
|
60
78
|
|
61
79
|
PLATFORMS
|
@@ -1,62 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "virtus"
|
4
|
+
|
3
5
|
module Norma43
|
4
6
|
module Models
|
5
7
|
class Account
|
6
|
-
include
|
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
|
8
|
+
include Virtus.model
|
23
9
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
10
|
+
attribute :bank_code
|
11
|
+
attribute :branch_code
|
12
|
+
attribute :account_number
|
13
|
+
attribute :start_date
|
14
|
+
attribute :end_date
|
15
|
+
attribute :balance_code
|
16
|
+
attribute :balance_amount
|
17
|
+
attribute :currency_code
|
18
|
+
attribute :information_mode_code
|
19
|
+
attribute :abbreviated_name
|
20
|
+
attribute :debit_entries
|
21
|
+
attribute :debit_amount
|
22
|
+
attribute :credit_entries
|
23
|
+
attribute :credit_amount
|
24
|
+
attribute :transactions, Array[Transaction]
|
57
25
|
|
58
26
|
def iban
|
59
|
-
SpanishIban.from_account(self)
|
27
|
+
@iban ||= SpanishIban.from_account(self)
|
60
28
|
end
|
61
29
|
end
|
62
30
|
end
|
@@ -1,22 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "virtus"
|
4
|
+
|
3
5
|
module Norma43
|
4
6
|
module Models
|
5
7
|
class AdditionalCurrency
|
6
|
-
include
|
7
|
-
|
8
|
-
attr_accessor :data_code, :currency_code, :amount, :free
|
8
|
+
include Virtus.model
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@free = Hash(attributes).values_at(
|
15
|
-
:data_code,
|
16
|
-
:currency_code,
|
17
|
-
:amount,
|
18
|
-
:free)
|
19
|
-
end
|
10
|
+
attribute :data_code
|
11
|
+
attribute :currency_code
|
12
|
+
attribute :amount
|
13
|
+
attribute :free
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "virtus"
|
4
|
+
|
3
5
|
module Norma43
|
4
6
|
module Models
|
5
7
|
class AdditionalItem
|
6
|
-
include
|
7
|
-
|
8
|
-
attr_accessor :data_code, :item_1, :item_2
|
8
|
+
include Virtus.model
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@item_2 = Hash(attributes).values_at(
|
14
|
-
:data_code,
|
15
|
-
:item_1,
|
16
|
-
:item_2)
|
17
|
-
end
|
10
|
+
attribute :data_code
|
11
|
+
attribute :item_1
|
12
|
+
attribute :item_2
|
18
13
|
end
|
19
14
|
end
|
20
15
|
end
|
@@ -1,41 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "virtus"
|
4
|
+
|
3
5
|
module Norma43
|
4
6
|
module Models
|
5
7
|
class Document
|
6
|
-
include
|
7
|
-
|
8
|
-
attr_accessor :id, :created_at, :delivery_number, :file_type, :name, :number_of_lines, :accounts
|
8
|
+
include Virtus.model
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
10
|
+
attribute :id
|
11
|
+
attribute :created_at
|
12
|
+
attribute :delivery_number
|
13
|
+
attribute :file_type
|
14
|
+
attribute :name
|
15
|
+
attribute :number_of_lines
|
16
|
+
attribute :accounts, Array[Account]
|
27
17
|
|
28
|
-
# @deprecated Please ask each transaction inside accounts for their transaction_date instead
|
29
18
|
def transaction_date
|
30
|
-
|
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
|
19
|
+
accounts.map(&:date).compact.first
|
39
20
|
end
|
40
21
|
end
|
41
22
|
end
|
@@ -1,50 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "virtus"
|
4
|
+
|
3
5
|
module Norma43
|
4
6
|
module Models
|
5
7
|
class Transaction
|
6
|
-
include
|
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
|
8
|
+
include Virtus.model
|
47
9
|
|
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
|
48
22
|
def debit?; self.amount_code == DEBIT_CODE end
|
49
23
|
end
|
50
24
|
end
|
data/lib/norma43/models.rb
CHANGED
data/lib/norma43/version.rb
CHANGED
data/norma43_parser.gemspec
CHANGED
@@ -19,6 +19,7 @@ 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"
|
22
23
|
spec.add_runtime_dependency "zeitwerk", "~> 2.0"
|
23
24
|
|
24
25
|
spec.add_development_dependency "rake", "~> 13.0"
|
@@ -3,7 +3,10 @@
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
5
|
RSpec.describe AccountEnd do
|
6
|
-
let
|
6
|
+
let :line do
|
7
|
+
double "Line", attributes: {}
|
8
|
+
end
|
9
|
+
|
7
10
|
let(:account) { Norma43::Models::Account.new }
|
8
11
|
let(:contexts) { Norma43::Utils::Contexts.new(
|
9
12
|
[
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe AccountStart do
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe "AccountStart" do
|
6
|
+
let(:line) { double "Line", 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) { 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 AdditionalCurrency do
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe "AdditionalCurrency" do
|
6
|
+
let(:line) { double "Line", 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) { 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 "AdditionalItems" do
|
6
|
+
let(:line) { double "Line", 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) { double "Models::AdditionalItem" }
|
26
26
|
before do
|
27
27
|
allow(Models::AdditionalItem).to receive(:new) { fake_additional_item }
|
28
28
|
end
|
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe DocumentEnd do
|
6
|
-
|
5
|
+
RSpec.describe "DocumentEnd" do
|
6
|
+
class Thing
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:line) { double "Line", record_number: 35 }
|
7
10
|
|
8
11
|
it "moves to the nearest document context" do
|
9
12
|
document = Norma43::Models::Document.new
|
10
|
-
contexts = Norma43::Utils::Contexts.new [
|
13
|
+
contexts = Norma43::Utils::Contexts.new [Thing.new, document, Thing.new, Thing.new]
|
11
14
|
|
12
15
|
DocumentEnd.call line, contexts
|
13
16
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Norma43
|
4
4
|
module LineProcessors
|
5
|
-
RSpec.describe DocumentStart do
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe "DocumentStart" do
|
6
|
+
let (:line) { double "Line", 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 = 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 Transaction do
|
6
|
-
let(:line) {
|
5
|
+
RSpec.describe "Transaction" do
|
6
|
+
let(:line) { double "Line", 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) { double "Models::Transaction" }
|
26
26
|
before do
|
27
27
|
allow(Models::Transaction).to receive(:new) { fake_transaction }
|
28
28
|
end
|
@@ -3,51 +3,17 @@
|
|
3
3
|
module Norma43
|
4
4
|
module Models
|
5
5
|
RSpec.describe Account do
|
6
|
-
it_behaves_like "a model"
|
7
|
-
|
8
6
|
describe "#iban" do
|
9
|
-
it { is_expected.to respond_to
|
7
|
+
it { is_expected.to respond_to :iban }
|
10
8
|
|
11
9
|
context "with the example in the documentation" do
|
12
|
-
it "
|
10
|
+
it "delegates to SpanishIban to return a IBAN string" do
|
13
11
|
account = subject
|
14
|
-
account.
|
15
|
-
account.
|
16
|
-
|
17
|
-
|
18
|
-
expect(account.iban).to eq("ES5400810054180001234567")
|
12
|
+
allow(Account::SpanishIban).to receive(:from_account).with(account).and_return("ES0000000000000000000123")
|
13
|
+
expect(account.iban).to eq("ES0000000000000000000123")
|
14
|
+
expect(Account::SpanishIban).to have_received(:from_account).with(account)
|
19
15
|
end
|
20
16
|
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
|
51
17
|
end
|
52
18
|
end
|
53
19
|
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 = double "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,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "norma43"
|
4
|
-
|
5
3
|
RSpec.configure do |config|
|
6
4
|
config.order = :random
|
7
5
|
Kernel.srand config.seed
|
@@ -13,7 +11,6 @@ RSpec.configure do |config|
|
|
13
11
|
config.mock_with :rspec do |mocks|
|
14
12
|
mocks.syntax = :expect
|
15
13
|
mocks.verify_partial_doubles = true
|
16
|
-
mocks.verify_doubled_constant_names = true
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norma43_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sequra engineering
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-06-19 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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: zeitwerk
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,7 +77,6 @@ files:
|
|
63
77
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
64
78
|
- ".github/workflows/ci.yml"
|
65
79
|
- ".github/workflows/release.yml"
|
66
|
-
- ".rspec"
|
67
80
|
- ".rubocop.yml"
|
68
81
|
- CHANGELOG.md
|
69
82
|
- Gemfile
|
@@ -91,7 +104,6 @@ files:
|
|
91
104
|
- lib/norma43/models/additional_currency.rb
|
92
105
|
- lib/norma43/models/additional_item.rb
|
93
106
|
- lib/norma43/models/document.rb
|
94
|
-
- lib/norma43/models/mixins/attributes_assignment.rb
|
95
107
|
- lib/norma43/models/transaction.rb
|
96
108
|
- lib/norma43/parser.rb
|
97
109
|
- lib/norma43/utils/contexts.rb
|
@@ -111,18 +123,15 @@ files:
|
|
111
123
|
- spec/norma43/line_processors/account_end_spec.rb
|
112
124
|
- spec/norma43/line_processors/account_start_spec.rb
|
113
125
|
- spec/norma43/line_processors/additional_currency_spec.rb
|
114
|
-
- spec/norma43/line_processors/
|
126
|
+
- spec/norma43/line_processors/additional_items_spec.rb
|
115
127
|
- spec/norma43/line_processors/document_end_spec.rb
|
116
128
|
- spec/norma43/line_processors/document_start_spec.rb
|
117
129
|
- spec/norma43/line_processors/transaction_spec.rb
|
118
130
|
- spec/norma43/models/account/spanish_iban_spec.rb
|
119
131
|
- spec/norma43/models/account_spec.rb
|
120
|
-
- spec/norma43/models/document_spec.rb
|
121
|
-
- spec/norma43/models/transaction_spec.rb
|
122
132
|
- spec/norma43/parser_spec.rb
|
123
133
|
- spec/norma43_spec.rb
|
124
134
|
- spec/spec_helper.rb
|
125
|
-
- spec/support/shared_examples_for_models.rb
|
126
135
|
- spec/support/shared_examples_for_values_line_parsers.rb
|
127
136
|
homepage: https://github.com/sequra/norma43_parser
|
128
137
|
licenses:
|
@@ -160,16 +169,13 @@ test_files:
|
|
160
169
|
- spec/norma43/line_processors/account_end_spec.rb
|
161
170
|
- spec/norma43/line_processors/account_start_spec.rb
|
162
171
|
- spec/norma43/line_processors/additional_currency_spec.rb
|
163
|
-
- spec/norma43/line_processors/
|
172
|
+
- spec/norma43/line_processors/additional_items_spec.rb
|
164
173
|
- spec/norma43/line_processors/document_end_spec.rb
|
165
174
|
- spec/norma43/line_processors/document_start_spec.rb
|
166
175
|
- spec/norma43/line_processors/transaction_spec.rb
|
167
176
|
- spec/norma43/models/account/spanish_iban_spec.rb
|
168
177
|
- spec/norma43/models/account_spec.rb
|
169
|
-
- spec/norma43/models/document_spec.rb
|
170
|
-
- spec/norma43/models/transaction_spec.rb
|
171
178
|
- spec/norma43/parser_spec.rb
|
172
179
|
- spec/norma43_spec.rb
|
173
180
|
- spec/spec_helper.rb
|
174
|
-
- spec/support/shared_examples_for_models.rb
|
175
181
|
- spec/support/shared_examples_for_values_line_parsers.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--require spec_helper
|
@@ -1,33 +0,0 @@
|
|
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,35 +0,0 @@
|
|
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
|
@@ -1,25 +0,0 @@
|
|
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
|
@@ -1,61 +0,0 @@
|
|
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
|