norma43_parser 1.0.1 → 2.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/.rubocop.yml +234 -0
- data/Gemfile +7 -1
- data/Gemfile.lock +73 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/lib/norma43.rb +9 -3
- 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/norma43_parser.gemspec +11 -9
- 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 -32
- data/lib/norma43/line_parsers/line_parsers.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa97b81f1bb849805abeb4e56fef5007ffed9d4a0a8347dd36978aa65a6811db
|
4
|
+
data.tar.gz: 12a3871952c37275766d7829e519031af30dce4f80f100d80c903093ab61260d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e229a6d2b0ad3ca3d7d870b8bf2fadbf34fb0287963a92ce33b8b9988b2cca2d37dd9eb34f4d8fcc23debb4aadfcae15a27496fb0e4458e73cd83a2bd4dde6f
|
7
|
+
data.tar.gz: f1554bc94bb3124519e687f042ec7600eb86e9945e19d5cd2b8527db4bed8d60d0f86a83379c220fd9abd667c3c1c9c7b981cd87275820d67177d1466e74dc80
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
7
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
8
|
+
DisabledByDefault: true
|
9
|
+
Exclude:
|
10
|
+
- "**/tmp/**/*"
|
11
|
+
- "**/templates/**/*"
|
12
|
+
- "**/vendor/**/*"
|
13
|
+
|
14
|
+
Performance:
|
15
|
+
Exclude:
|
16
|
+
- "**/test/**/*"
|
17
|
+
|
18
|
+
# Prefer &&/|| over and/or.
|
19
|
+
Style/AndOr:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
# Align `when` with `case`.
|
23
|
+
Layout/CaseIndentation:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
# Align comments with method definitions.
|
27
|
+
Layout/CommentIndentation:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Layout/ElseAlignment:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
# Align `end` with the matching keyword or starting expression except for
|
34
|
+
# assignments, where it should be aligned with the LHS.
|
35
|
+
Layout/EndAlignment:
|
36
|
+
Enabled: true
|
37
|
+
EnforcedStyleAlignWith: variable
|
38
|
+
AutoCorrect: true
|
39
|
+
|
40
|
+
Layout/EmptyLineAfterMagicComment:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Layout/EmptyLinesAroundAccessModifier:
|
44
|
+
Enabled: true
|
45
|
+
EnforcedStyle: only_before
|
46
|
+
|
47
|
+
Layout/EmptyLinesAroundBlockBody:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
# In a regular class definition, no empty lines around the body.
|
51
|
+
Layout/EmptyLinesAroundClassBody:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
# In a regular method definition, no empty lines around the body.
|
55
|
+
Layout/EmptyLinesAroundMethodBody:
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
# In a regular module definition, no empty lines around the body.
|
59
|
+
Layout/EmptyLinesAroundModuleBody:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
63
|
+
Style/HashSyntax:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Layout/IndentFirstArgument:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
70
|
+
# extra level of indentation.
|
71
|
+
Layout/IndentationConsistency:
|
72
|
+
Enabled: true
|
73
|
+
EnforcedStyle: indented_internal_methods
|
74
|
+
|
75
|
+
# Two spaces, no tabs (for indentation).
|
76
|
+
Layout/IndentationWidth:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Layout/LeadingCommentSpace:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Layout/SpaceAfterColon:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Layout/SpaceAfterComma:
|
86
|
+
Enabled: true
|
87
|
+
|
88
|
+
Layout/SpaceAfterSemicolon:
|
89
|
+
Enabled: true
|
90
|
+
|
91
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
Layout/SpaceAroundKeyword:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
Layout/SpaceBeforeComma:
|
98
|
+
Enabled: true
|
99
|
+
|
100
|
+
Layout/SpaceBeforeComment:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
Layout/SpaceBeforeFirstArg:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
Style/DefWithParentheses:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
# Defining a method with parameters needs parentheses.
|
110
|
+
Style/MethodDefParentheses:
|
111
|
+
Enabled: true
|
112
|
+
|
113
|
+
Style/FrozenStringLiteralComment:
|
114
|
+
Enabled: true
|
115
|
+
EnforcedStyle: always
|
116
|
+
Exclude:
|
117
|
+
- "actionview/test/**/*.builder"
|
118
|
+
- "actionview/test/**/*.ruby"
|
119
|
+
- "actionpack/test/**/*.builder"
|
120
|
+
- "actionpack/test/**/*.ruby"
|
121
|
+
- "activestorage/db/migrate/**/*.rb"
|
122
|
+
- "activestorage/db/update_migrate/**/*.rb"
|
123
|
+
- "actionmailbox/db/migrate/**/*.rb"
|
124
|
+
- "actiontext/db/migrate/**/*.rb"
|
125
|
+
|
126
|
+
Style/RedundantFreeze:
|
127
|
+
Enabled: true
|
128
|
+
|
129
|
+
# Use `foo {}` not `foo{}`.
|
130
|
+
Layout/SpaceBeforeBlockBraces:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
# Use `foo { bar }` not `foo {bar}`.
|
134
|
+
Layout/SpaceInsideBlockBraces:
|
135
|
+
Enabled: true
|
136
|
+
EnforcedStyleForEmptyBraces: space
|
137
|
+
|
138
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
139
|
+
Layout/SpaceInsideHashLiteralBraces:
|
140
|
+
Enabled: true
|
141
|
+
|
142
|
+
Layout/SpaceInsideParens:
|
143
|
+
Enabled: true
|
144
|
+
|
145
|
+
# Check quotes usage according to lint rule below.
|
146
|
+
Style/StringLiterals:
|
147
|
+
Enabled: true
|
148
|
+
EnforcedStyle: double_quotes
|
149
|
+
|
150
|
+
# Detect hard tabs, no hard tabs.
|
151
|
+
Layout/Tab:
|
152
|
+
Enabled: true
|
153
|
+
|
154
|
+
# Blank lines should not have any spaces.
|
155
|
+
Layout/TrailingBlankLines:
|
156
|
+
Enabled: true
|
157
|
+
|
158
|
+
# No trailing whitespace.
|
159
|
+
Layout/TrailingWhitespace:
|
160
|
+
Enabled: true
|
161
|
+
|
162
|
+
# Use quotes for string literals when they are enough.
|
163
|
+
Style/UnneededPercentQ:
|
164
|
+
Enabled: true
|
165
|
+
|
166
|
+
Lint/AmbiguousOperator:
|
167
|
+
Enabled: true
|
168
|
+
|
169
|
+
Lint/AmbiguousRegexpLiteral:
|
170
|
+
Enabled: true
|
171
|
+
|
172
|
+
Lint/ErbNewArguments:
|
173
|
+
Enabled: true
|
174
|
+
|
175
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
176
|
+
Lint/RequireParentheses:
|
177
|
+
Enabled: true
|
178
|
+
|
179
|
+
Lint/ShadowingOuterLocalVariable:
|
180
|
+
Enabled: true
|
181
|
+
|
182
|
+
Lint/StringConversionInInterpolation:
|
183
|
+
Enabled: true
|
184
|
+
|
185
|
+
Lint/UriEscapeUnescape:
|
186
|
+
Enabled: true
|
187
|
+
|
188
|
+
Lint/UselessAssignment:
|
189
|
+
Enabled: true
|
190
|
+
|
191
|
+
Lint/DeprecatedClassMethods:
|
192
|
+
Enabled: true
|
193
|
+
|
194
|
+
Style/ParenthesesAroundCondition:
|
195
|
+
Enabled: true
|
196
|
+
|
197
|
+
Style/RedundantBegin:
|
198
|
+
Enabled: true
|
199
|
+
|
200
|
+
Style/RedundantReturn:
|
201
|
+
Enabled: true
|
202
|
+
AllowMultipleReturnValues: true
|
203
|
+
|
204
|
+
Style/Semicolon:
|
205
|
+
Enabled: true
|
206
|
+
AllowAsExpressionSeparator: true
|
207
|
+
|
208
|
+
# Prefer Foo.method over Foo::method
|
209
|
+
Style/ColonMethodCall:
|
210
|
+
Enabled: true
|
211
|
+
|
212
|
+
Style/TrivialAccessors:
|
213
|
+
Enabled: true
|
214
|
+
|
215
|
+
Performance/FlatMap:
|
216
|
+
Enabled: true
|
217
|
+
|
218
|
+
Performance/RedundantMerge:
|
219
|
+
Enabled: true
|
220
|
+
|
221
|
+
Performance/StartWith:
|
222
|
+
Enabled: true
|
223
|
+
|
224
|
+
Performance/EndWith:
|
225
|
+
Enabled: true
|
226
|
+
|
227
|
+
Performance/RegexpMatch:
|
228
|
+
Enabled: true
|
229
|
+
|
230
|
+
Performance/ReverseEach:
|
231
|
+
Enabled: true
|
232
|
+
|
233
|
+
Performance/UnfreezeString:
|
234
|
+
Enabled: true
|
data/Gemfile
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
|
5
|
+
group :development, :test do
|
6
|
+
gem "rubocop", ">= 0.75", require: false
|
7
|
+
gem "rubocop-performance", require: false
|
8
|
+
end
|
9
|
+
|
4
10
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
norma43_parser (2.0.0)
|
5
|
+
virtus (~> 1.0)
|
6
|
+
zeitwerk (~> 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
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
|
+
diff-lcs (1.3)
|
21
|
+
equalizer (0.0.11)
|
22
|
+
ice_nine (0.11.2)
|
23
|
+
jaro_winkler (1.5.3)
|
24
|
+
parallel (1.18.0)
|
25
|
+
parser (2.6.5.0)
|
26
|
+
ast (~> 2.4.0)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (10.5.0)
|
29
|
+
rspec (3.9.0)
|
30
|
+
rspec-core (~> 3.9.0)
|
31
|
+
rspec-expectations (~> 3.9.0)
|
32
|
+
rspec-mocks (~> 3.9.0)
|
33
|
+
rspec-core (3.9.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-expectations (3.9.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-mocks (3.9.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.9.0)
|
41
|
+
rspec-support (3.9.0)
|
42
|
+
rubocop (0.75.0)
|
43
|
+
jaro_winkler (~> 1.5.1)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 2.6)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
49
|
+
rubocop-performance (1.5.0)
|
50
|
+
rubocop (>= 0.71.0)
|
51
|
+
ruby-progressbar (1.10.1)
|
52
|
+
thread_safe (0.3.6)
|
53
|
+
unicode-display_width (1.6.0)
|
54
|
+
virtus (1.0.5)
|
55
|
+
axiom-types (~> 0.1)
|
56
|
+
coercible (~> 1.0)
|
57
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
58
|
+
equalizer (~> 0.0, >= 0.0.9)
|
59
|
+
zeitwerk (2.2.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
bundler (~> 1.0)
|
66
|
+
norma43_parser!
|
67
|
+
rake (~> 10.0)
|
68
|
+
rspec (~> 3.0)
|
69
|
+
rubocop (>= 0.75)
|
70
|
+
rubocop-performance
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
1.17.3
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ gem 'norma43_parser', git: "git@github.com:sequra/norma43_parser.git"
|
|
14
14
|
require "norma43"
|
15
15
|
|
16
16
|
norma43_file_contents = File.open("path_to_file.n43", encoding: "iso-8859-1")
|
17
|
-
document =
|
17
|
+
document = Norma43.parse norma43_file_contents
|
18
18
|
```
|
19
19
|
|
20
20
|
### Document
|
data/Rakefile
CHANGED
data/lib/norma43.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
|
5
|
+
loader = Zeitwerk::Loader.for_gem
|
6
|
+
loader.setup # ready!
|
3
7
|
|
4
8
|
module Norma43
|
5
|
-
def self.parse
|
9
|
+
def self.parse(text)
|
6
10
|
Parser.new(text).result
|
7
11
|
end
|
8
12
|
end
|
13
|
+
|
14
|
+
loader.eager_load
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "norma43/line_processors"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Norma43
|
5
4
|
module LineHandlers
|
@@ -44,7 +43,7 @@ module Norma43
|
|
44
43
|
end
|
45
44
|
|
46
45
|
Handler = Struct.new :parser, :processor do
|
47
|
-
def process
|
46
|
+
def process(line, contexts)
|
48
47
|
line_parser = self.parser.new(line)
|
49
48
|
|
50
49
|
processor.call line_parser, contexts
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Norma43
|
4
|
+
module LineParsers
|
5
|
+
class AccountEnd < LineParser
|
6
|
+
field :bank_code, 2..5, :integer
|
7
|
+
field :branch_code, 6..9, :integer
|
8
|
+
field :account_number, 10..19, :integer
|
9
|
+
field :debit_entries, 20..24, :integer
|
10
|
+
field :debit_amount, 25..38, :integer
|
11
|
+
field :credit_entries, 39..43, :integer
|
12
|
+
field :credit_amount, 44..57, :integer
|
13
|
+
field :balance_code, 58, :integer
|
14
|
+
field :balance_amount, 59..72, :integer
|
15
|
+
field :currency_code, 73..75, :integer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Norma43
|
4
|
+
module LineParsers
|
5
|
+
class AccountStart < LineParser
|
6
|
+
field :bank_code, 2..5, :integer
|
7
|
+
field :branch_code, 6..9, :integer
|
8
|
+
field :account_number, 10..19, :integer
|
9
|
+
field :start_date, 20..25, :date
|
10
|
+
field :end_date, 26..31, :date
|
11
|
+
field :balance_code, 32, :integer
|
12
|
+
field :balance_amount, 33..46, :integer
|
13
|
+
field :currency_code, 47..49, :integer
|
14
|
+
field :information_mode_code, 50, :integer
|
15
|
+
field :abbreviated_name, 51..76
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|