-
Notifications
You must be signed in to change notification settings - Fork 0
Add header record using Fixy and DryRB Validation gems #5
Changes from 1 commit
d42619e
2cd34cc
1bcde41
860fea8
013c5d5
6d3a77d
3134987
0301fc8
6ad1f19
f45fa5f
02f2207
a2dfdf5
f34f6e1
c3e20e1
16ca73c
1d1271a
629c35f
8767d78
f79a8b8
07a98a1
d983493
7fd5cd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,23 @@ require: | |
|
|
||
| AllCops: | ||
| NewCops: enable | ||
| TargetRubyVersion: 2.6 | ||
| TargetRubyVersion: 2.7 | ||
|
|
||
| Layout/LineLength: | ||
| Max: 120 | ||
|
|
||
| Metrics/BlockLength: | ||
| Enabled: false | ||
|
|
||
| Style/Documentation: | ||
| Enabled: false | ||
|
|
||
| Style/StringLiterals: | ||
| Enabled: true | ||
| EnforcedStyle: double_quotes | ||
|
|
||
| Style/StringLiteralsInInterpolation: | ||
| Enabled: true | ||
| EnforcedStyle: double_quotes | ||
| RSpec/ExampleLength: | ||
| Enabled: false | ||
|
|
||
| Layout/LineLength: | ||
| Max: 120 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probs copy the current rubocop yml we have in zfp and split(main zepto) repos |
||
| RSpec/MultipleExpectations: | ||
| Enabled: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "formatters" | ||
|
|
||
| module MT9 | ||
| class BaseRecord < Fixy::Record | ||
| include Fixy::Formatter::Alphanumeric | ||
| include Fixy::Formatter::Numeric | ||
|
|
||
| SPACE = " " | ||
|
|
||
| set_record_length 160 | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Fixy | ||
| module Formatter | ||
| module Numeric | ||
| RESERVED_BANK_CODES = %w[99].freeze | ||
|
|
||
| def format_numeric(input, length) | ||
| input = input.to_s | ||
| raise ArgumentError, "Invalid Input (only digits are accepted)" unless input =~ /^\d+$/ | ||
| raise ArgumentError, "Invalid Length (length must be #{length} not #{input.length})" if input.length != length | ||
|
|
||
| input | ||
| end | ||
|
|
||
| def format_file_type(input, _length) | ||
| input = input.to_s | ||
| unless MT9::HeaderRecord::FILE_TYPES.include?(input) | ||
| raise( | ||
| ArgumentError, | ||
| "Invalid filetype. Must be one of the following: #{MT9::HeaderRecord::FILE_TYPES.join(', ')}" | ||
| ) | ||
| end | ||
|
|
||
| input | ||
| end | ||
|
|
||
| def format_account_number(input, length) | ||
| input = format_numeric(input, length) | ||
| if input.start_with?(*RESERVED_BANK_CODES) | ||
| raise ArgumentError, "Invalid account number. Cannot start with a reserved bank code" | ||
| end | ||
|
|
||
| input | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| # frozen_string_literal: true | ||||||
|
|
||||||
| module MT9 | ||||||
| class HeaderRecord < BaseRecord | ||||||
| DIRECT_CREDIT = "12" | ||||||
| DIRECT_DEBIT = "20" | ||||||
| FILE_TYPES = [DIRECT_CREDIT, DIRECT_DEBIT].freeze | ||||||
|
|
||||||
| attr_reader :file_type, :account_number, :due_date, :client_short_name | ||||||
|
|
||||||
| field :file_type, 2, "1-2", :file_type | ||||||
| field :account_number, 15, "3-17", :account_number | ||||||
|
||||||
| field :filler1, 1, "18", :alphanumeric | ||||||
| field :due_date, 6, "19-24", :numeric | ||||||
| field :filler7, 7, "25-31", :alphanumeric | ||||||
| field :client_short_name, 20, "32-51", :alphanumeric | ||||||
| field :filler109, 109, "52-160", :alphanumeric | ||||||
|
|
||||||
| field_value :filler1, SPACE | ||||||
| field_value :filler7, SPACE * 7 | ||||||
| field_value :filler109, SPACE * 109 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lots of "magic numbers" here. I would try to name them here and make them constants. i.e. 109 could be
Suggested change
|
||||||
|
|
||||||
| def initialize(file_type:, account_number:, due_date:, client_short_name:) | ||||||
| @file_type = file_type | ||||||
| @account_number = account_number | ||||||
| @due_date = due_date | ||||||
| @client_short_name = client_short_name | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason we're not in 3.0.3 land?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the version specified in the gemspec, and I think it's best if the gem can support as wide a range of Ruby versions as possible (albeit support for 2.7 will be dropped in 10 months)