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.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +13 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
  4. data/.rubocop.yml +234 -0
  5. data/Gemfile +7 -1
  6. data/Gemfile.lock +73 -0
  7. data/README.md +1 -1
  8. data/Rakefile +2 -0
  9. data/lib/norma43.rb +9 -3
  10. data/lib/norma43/line_handlers.rb +2 -3
  11. data/lib/norma43/line_parsers/account_end.rb +18 -0
  12. data/lib/norma43/line_parsers/account_start.rb +18 -0
  13. data/lib/norma43/line_parsers/additional_currency.rb +12 -0
  14. data/lib/norma43/line_parsers/additional_item.rb +11 -0
  15. data/lib/norma43/line_parsers/document_end.rb +9 -0
  16. data/lib/norma43/line_parsers/document_start.rb +13 -0
  17. data/lib/norma43/line_parsers/file_format_validator.rb +15 -12
  18. data/lib/norma43/line_parsers/line_parser.rb +29 -28
  19. data/lib/norma43/line_parsers/transaction.rb +18 -0
  20. data/lib/norma43/line_processors.rb +2 -2
  21. data/lib/norma43/models.rb +5 -4
  22. data/lib/norma43/parser.rb +38 -42
  23. data/lib/norma43/utils/contexts.rb +40 -37
  24. data/lib/norma43/utils/string_helpers.rb +10 -6
  25. data/lib/norma43/utils/typecaster.rb +16 -12
  26. data/lib/norma43/version.rb +3 -1
  27. data/norma43_parser.gemspec +11 -9
  28. data/spec/example1_parse_spec.rb +12 -11
  29. data/spec/norma43/line_parsers/account_end_spec.rb +1 -1
  30. data/spec/norma43/line_parsers/account_start_spec.rb +1 -2
  31. data/spec/norma43/line_parsers/additional_currency_spec.rb +1 -1
  32. data/spec/norma43/line_parsers/additional_items_spec.rb +1 -1
  33. data/spec/norma43/line_parsers/document_end_spec.rb +1 -2
  34. data/spec/norma43/line_parsers/document_start_spec.rb +1 -1
  35. data/spec/norma43/line_parsers/transaction_spec.rb +1 -3
  36. data/spec/norma43/line_processors/account_end_spec.rb +6 -8
  37. data/spec/norma43/line_processors/account_start_spec.rb +8 -9
  38. data/spec/norma43/line_processors/additional_currency_spec.rb +6 -7
  39. data/spec/norma43/line_processors/additional_items_spec.rb +6 -7
  40. data/spec/norma43/line_processors/document_end_spec.rb +5 -6
  41. data/spec/norma43/line_processors/document_start_spec.rb +3 -4
  42. data/spec/norma43/line_processors/transaction_spec.rb +6 -7
  43. data/spec/norma43/parser_spec.rb +5 -4
  44. data/spec/norma43_spec.rb +2 -0
  45. data/spec/spec_helper.rb +1 -4
  46. data/spec/support/shared_examples_for_values_line_parsers.rb +2 -0
  47. metadata +41 -32
  48. data/lib/norma43/line_parsers/line_parsers.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4efe95db38bc547fc36d8f649c83f65a90a078b2
4
- data.tar.gz: 04d5b299d47f187c907aa2b15725a9adf96fe20b
2
+ SHA256:
3
+ metadata.gz: fa97b81f1bb849805abeb4e56fef5007ffed9d4a0a8347dd36978aa65a6811db
4
+ data.tar.gz: 12a3871952c37275766d7829e519031af30dce4f80f100d80c903093ab61260d
5
5
  SHA512:
6
- metadata.gz: 972ca63a8512c51a2dd6100cf5570d942bf39ed5bb4d97856231ece753a8dcf1de916505ac3019aa163c1fe581ea59a69256d9a3f9ea927354c13dc4338f0147
7
- data.tar.gz: 4893dd41e41ccd78f47f63fa10007b989576be1826fad09f9eb017a3604667ebb3dc33ea5a7a2f0b047638eab360e7c42535029bfaa3c0e085bf110f93f20a31
6
+ metadata.gz: 1e229a6d2b0ad3ca3d7d870b8bf2fadbf34fb0287963a92ce33b8b9988b2cca2d37dd9eb34f4d8fcc23debb4aadfcae15a27496fb0e4458e73cd83a2bd4dde6f
7
+ data.tar.gz: f1554bc94bb3124519e687f042ec7600eb86e9945e19d5cd2b8527db4bed8d60d0f86a83379c220fd9abd667c3c1c9c7b981cd87275820d67177d1466e74dc80
@@ -0,0 +1,13 @@
1
+ ## Expected Behavior
2
+
3
+ ## Actual Behavior
4
+
5
+ ## Steps to Reproduce the Problem
6
+
7
+ 1.
8
+
9
+ ## Specifications
10
+
11
+ - Version:
12
+ - Platform:
13
+ - Subsystem:
@@ -0,0 +1,5 @@
1
+ Fixes #
2
+
3
+ ## Proposed Changes
4
+
5
+ -
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
- gem "codeclimate-test-reporter", group: :test, require: nil
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 = norma43.parse norma43_file_contents
17
+ document = Norma43.parse norma43_file_contents
18
18
  ```
19
19
 
20
20
  ### Document
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
data/lib/norma43.rb CHANGED
@@ -1,8 +1,14 @@
1
- require "norma43/version"
2
- require "norma43/parser"
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 text
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
- require "norma43/line_parsers/line_parsers"
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 line, contexts
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