norma43_parser 1.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +13 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
- data/.github/workflows/ci.yml +22 -0
- data/.rubocop.yml +234 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +7 -1
- data/Gemfile.lock +72 -0
- data/README.md +6 -4
- data/Rakefile +2 -0
- data/lib/norma43/line_handlers.rb +2 -3
- data/lib/norma43/line_parsers/account_end.rb +18 -0
- data/lib/norma43/line_parsers/account_start.rb +18 -0
- data/lib/norma43/line_parsers/additional_currency.rb +12 -0
- data/lib/norma43/line_parsers/additional_item.rb +11 -0
- data/lib/norma43/line_parsers/document_end.rb +9 -0
- data/lib/norma43/line_parsers/document_start.rb +13 -0
- data/lib/norma43/line_parsers/file_format_validator.rb +15 -12
- data/lib/norma43/line_parsers/line_parser.rb +29 -28
- data/lib/norma43/line_parsers/transaction.rb +18 -0
- data/lib/norma43/line_processors.rb +2 -2
- data/lib/norma43/models.rb +5 -4
- data/lib/norma43/parser.rb +38 -42
- data/lib/norma43/utils/contexts.rb +40 -37
- data/lib/norma43/utils/string_helpers.rb +10 -6
- data/lib/norma43/utils/typecaster.rb +16 -12
- data/lib/norma43/version.rb +3 -1
- data/lib/norma43.rb +9 -3
- data/norma43_parser.gemspec +10 -10
- data/spec/example1_parse_spec.rb +12 -11
- data/spec/norma43/line_parsers/account_end_spec.rb +1 -1
- data/spec/norma43/line_parsers/account_start_spec.rb +1 -2
- data/spec/norma43/line_parsers/additional_currency_spec.rb +1 -1
- data/spec/norma43/line_parsers/additional_items_spec.rb +1 -1
- data/spec/norma43/line_parsers/document_end_spec.rb +1 -2
- data/spec/norma43/line_parsers/document_start_spec.rb +1 -1
- data/spec/norma43/line_parsers/transaction_spec.rb +1 -3
- data/spec/norma43/line_processors/account_end_spec.rb +6 -8
- data/spec/norma43/line_processors/account_start_spec.rb +8 -9
- data/spec/norma43/line_processors/additional_currency_spec.rb +6 -7
- data/spec/norma43/line_processors/additional_items_spec.rb +6 -7
- data/spec/norma43/line_processors/document_end_spec.rb +5 -6
- data/spec/norma43/line_processors/document_start_spec.rb +3 -4
- data/spec/norma43/line_processors/transaction_spec.rb +6 -7
- data/spec/norma43/parser_spec.rb +5 -4
- data/spec/norma43_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/support/shared_examples_for_values_line_parsers.rb +2 -0
- metadata +41 -44
- data/lib/norma43/line_parsers/line_parsers.rb +0 -69
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "norma43/line_processors"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Norma43
|
5
4
|
module LineProcessors
|
@@ -10,8 +9,8 @@ module Norma43
|
|
10
9
|
let(:line) { double "Line", record_number: 35 }
|
11
10
|
|
12
11
|
it "moves to the nearest document context" do
|
13
|
-
document = Models::Document.new
|
14
|
-
contexts = Contexts.new [Thing.new, document, Thing.new, Thing.new]
|
12
|
+
document = Norma43::Models::Document.new
|
13
|
+
contexts = Norma43::Utils::Contexts.new [Thing.new, document, Thing.new, Thing.new]
|
15
14
|
|
16
15
|
DocumentEnd.call line, contexts
|
17
16
|
|
@@ -19,9 +18,9 @@ module Norma43
|
|
19
18
|
end
|
20
19
|
|
21
20
|
it "sets the number of lines on the document" do
|
22
|
-
document = Models::Document.new
|
21
|
+
document = Norma43::Models::Document.new
|
23
22
|
|
24
|
-
DocumentEnd.call line, Contexts.new(document)
|
23
|
+
DocumentEnd.call line, Norma43::Utils::Contexts.new(document)
|
25
24
|
|
26
25
|
expect(document.number_of_lines).to eq 35
|
27
26
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "norma43/line_processors"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Norma43
|
5
4
|
module LineProcessors
|
@@ -9,7 +8,7 @@ module Norma43
|
|
9
8
|
it "instantiates a new document with the line attributes" do
|
10
9
|
allow(Models::Document).to receive :new
|
11
10
|
|
12
|
-
DocumentStart.call line, Contexts.new
|
11
|
+
DocumentStart.call line, Norma43::Utils::Contexts.new
|
13
12
|
|
14
13
|
expect(Models::Document).to have_received(:new).with line.attributes
|
15
14
|
end
|
@@ -18,7 +17,7 @@ module Norma43
|
|
18
17
|
fake_document = double "Models::Document"
|
19
18
|
allow(Models::Document).to receive(:new) { fake_document }
|
20
19
|
|
21
|
-
contexts = DocumentStart.call line, Contexts.new
|
20
|
+
contexts = DocumentStart.call line, Norma43::Utils::Contexts.new
|
22
21
|
|
23
22
|
expect(contexts.current).to be fake_document
|
24
23
|
end
|
@@ -1,16 +1,15 @@
|
|
1
|
-
|
2
|
-
require "norma43/line_processors"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Norma43
|
5
4
|
module LineProcessors
|
6
5
|
RSpec.describe "Transaction" do
|
7
|
-
let(:line){ double "Line", attributes: {} }
|
8
|
-
let(:account){ Models::Account.new }
|
9
|
-
let(:contexts){ Contexts.new(
|
6
|
+
let(:line) { double "Line", attributes: {} }
|
7
|
+
let(:account) { Norma43::Models::Account.new }
|
8
|
+
let(:contexts) { Norma43::Utils::Contexts.new(
|
10
9
|
[
|
11
|
-
Models::Document.new
|
10
|
+
Norma43::Models::Document.new,
|
12
11
|
account,
|
13
|
-
Models::Transaction.new
|
12
|
+
Norma43::Models::Transaction.new
|
14
13
|
])
|
15
14
|
}
|
16
15
|
|
data/spec/norma43/parser_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "norma43/parser"
|
2
4
|
|
3
5
|
module Norma43
|
@@ -5,18 +7,17 @@ module Norma43
|
|
5
7
|
describe "ensuring the file is valid" do
|
6
8
|
it "accepts a valid file starting with document" do
|
7
9
|
valid_file = "00TI222222 2011102504133012345601TL1Norma43 "
|
8
|
-
expect{ Parser.new(valid_file) }.to_not raise_error
|
10
|
+
expect { Parser.new(valid_file) }.to_not raise_error
|
9
11
|
end
|
10
12
|
|
11
13
|
it "accepts a valid file starting with an account" do
|
12
|
-
|
13
14
|
valid_file = "119999111101234567890408040409052000000001234569783MY ACCOUNT "
|
14
|
-
expect{ Parser.new(valid_file) }.to_not raise_error
|
15
|
+
expect { Parser.new(valid_file) }.to_not raise_error
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should start with 00 or 11" do
|
18
19
|
invalid_file = "99TI222222 2011102504133012345601TL1Norma43 "
|
19
|
-
expect{ Parser.new(invalid_file) }.to raise_error{ Norma43::InvalidFileFormatError }
|
20
|
+
expect { Parser.new(invalid_file) }.to raise_error { Norma43::InvalidFileFormatError }
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/spec/norma43_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,93 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norma43_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sequra engineering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: virtus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
20
|
-
type: :
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: zeitwerk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: virtus
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
description:
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
84
70
|
email:
|
85
71
|
- dev@sequra.es
|
86
72
|
executables: []
|
87
73
|
extensions: []
|
88
74
|
extra_rdoc_files: []
|
89
75
|
files:
|
76
|
+
- ".github/ISSUE_TEMPLATE.md"
|
77
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
78
|
+
- ".github/workflows/ci.yml"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- CHANGELOG.md
|
90
81
|
- Gemfile
|
82
|
+
- Gemfile.lock
|
91
83
|
- LICENSE
|
92
84
|
- README.md
|
93
85
|
- Rakefile
|
@@ -95,9 +87,15 @@ files:
|
|
95
87
|
- doc/cuaderno_43_-_junio_2012.pdf
|
96
88
|
- lib/norma43.rb
|
97
89
|
- lib/norma43/line_handlers.rb
|
90
|
+
- lib/norma43/line_parsers/account_end.rb
|
91
|
+
- lib/norma43/line_parsers/account_start.rb
|
92
|
+
- lib/norma43/line_parsers/additional_currency.rb
|
93
|
+
- lib/norma43/line_parsers/additional_item.rb
|
94
|
+
- lib/norma43/line_parsers/document_end.rb
|
95
|
+
- lib/norma43/line_parsers/document_start.rb
|
98
96
|
- lib/norma43/line_parsers/file_format_validator.rb
|
99
97
|
- lib/norma43/line_parsers/line_parser.rb
|
100
|
-
- lib/norma43/line_parsers/
|
98
|
+
- lib/norma43/line_parsers/transaction.rb
|
101
99
|
- lib/norma43/line_processors.rb
|
102
100
|
- lib/norma43/models.rb
|
103
101
|
- lib/norma43/parser.rb
|
@@ -130,24 +128,23 @@ homepage: https://github.com/sequra/norma43_parser
|
|
130
128
|
licenses:
|
131
129
|
- MIT
|
132
130
|
metadata: {}
|
133
|
-
post_install_message:
|
131
|
+
post_install_message:
|
134
132
|
rdoc_options: []
|
135
133
|
require_paths:
|
136
134
|
- lib
|
137
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
136
|
requirements:
|
139
|
-
- - "
|
137
|
+
- - ">="
|
140
138
|
- !ruby/object:Gem::Version
|
141
|
-
version: '2.
|
139
|
+
version: '2.6'
|
142
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
141
|
requirements:
|
144
142
|
- - ">="
|
145
143
|
- !ruby/object:Gem::Version
|
146
144
|
version: '0'
|
147
145
|
requirements: []
|
148
|
-
|
149
|
-
|
150
|
-
signing_key:
|
146
|
+
rubygems_version: 3.2.32
|
147
|
+
signing_key:
|
151
148
|
specification_version: 4
|
152
149
|
summary: Parses banks transactions files specified in rule 43
|
153
150
|
test_files:
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "norma43/line_parsers/line_parser"
|
2
|
-
|
3
|
-
module Norma43
|
4
|
-
module LineParsers
|
5
|
-
class DocumentStart < LineParser
|
6
|
-
field :id, 2..13
|
7
|
-
field :created_at, 14..33, :time
|
8
|
-
field :delivery_number, 34..35, :integer
|
9
|
-
field :file_type, 36..38
|
10
|
-
field :name, 39..48
|
11
|
-
end
|
12
|
-
|
13
|
-
class DocumentEnd < LineParser
|
14
|
-
field :record_number, 20..25, :integer
|
15
|
-
end
|
16
|
-
|
17
|
-
class AccountStart < LineParser
|
18
|
-
field :bank_code, 2..5, :integer
|
19
|
-
field :branch_code, 6..9, :integer
|
20
|
-
field :account_number, 10..19, :integer
|
21
|
-
field :start_date, 20..25, :date
|
22
|
-
field :end_date, 26..31, :date
|
23
|
-
field :balance_code, 32, :integer
|
24
|
-
field :balance_amount, 33..46, :integer
|
25
|
-
field :currency_code, 47..49, :integer
|
26
|
-
field :information_mode_code, 50, :integer
|
27
|
-
field :abbreviated_name, 51..76
|
28
|
-
end
|
29
|
-
|
30
|
-
class AccountEnd < LineParser
|
31
|
-
field :bank_code, 2..5, :integer
|
32
|
-
field :branch_code, 6..9, :integer
|
33
|
-
field :account_number, 10..19, :integer
|
34
|
-
field :debit_entries, 20..24, :integer
|
35
|
-
field :debit_amount, 25..38, :integer
|
36
|
-
field :credit_entries, 39..43, :integer
|
37
|
-
field :credit_amount, 44..57, :integer
|
38
|
-
field :balance_code, 58, :integer
|
39
|
-
field :balance_amount, 59..72, :integer
|
40
|
-
field :currency_code, 73..75, :integer
|
41
|
-
end
|
42
|
-
|
43
|
-
class Transaction < LineParser
|
44
|
-
field :origin_branch_code, 6..9, :integer
|
45
|
-
field :transaction_date, 10..15, :date
|
46
|
-
field :value_date, 16..21, :date
|
47
|
-
field :shared_item, 22..23, :integer
|
48
|
-
field :own_item, 24..26, :integer
|
49
|
-
field :amount_code, 27, :integer
|
50
|
-
field :amount, 28..41, :integer
|
51
|
-
field :document_number, 42..51, :integer
|
52
|
-
field :reference_1, 52..63, :integer
|
53
|
-
field :reference_2, 64..79
|
54
|
-
end
|
55
|
-
|
56
|
-
class AdditionalItem < LineParser
|
57
|
-
field :data_code, 2..3, :integer
|
58
|
-
field :item_1, 4..41
|
59
|
-
field :item_2, 42..79
|
60
|
-
end
|
61
|
-
|
62
|
-
class AdditionalCurrency < LineParser
|
63
|
-
field :data_code, 2..3, :integer
|
64
|
-
field :currency_code, 4..6, :integer
|
65
|
-
field :amount, 7..20, :integer
|
66
|
-
field :free, 21..79
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|