This repository was archived by the owner on Jun 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +32
-17
lines changed
Expand file tree Collapse file tree 5 files changed +32
-17
lines changed Original file line number Diff line number Diff line change 33require "dry-validation"
44require "fixy"
55
6- require_relative "mt9/base_record"
7- require_relative "mt9/header_record"
8- require_relative "mt9/version"
6+ require "mt9/values"
7+ require "mt9/validators/base_contract"
8+ require "mt9/validators/header_record_contract"
9+ require "mt9/base_record"
10+ require "mt9/header_record"
11+ require "mt9/version"
912
1013module MT9
1114 class ValidationError < StandardError
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- require_relative "validators/header_record_contract"
4-
53module MT9
64 class HeaderRecord < BaseRecord
75 set_line_ending Fixy ::Record ::LINE_ENDING_CRLF
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module MT9
4+ module Validators
5+ class BaseContract < Dry ::Validation ::Contract
6+ register_macro ( :is_account_number? ) do
7+ key . failure ( "must be 15 or 16 numeric characters" ) unless /^(\d {15}|\d {16})$/ . match ( value )
8+ key . failure ( "must not start with a reserved bank code" ) if value . start_with? ( *MT9 ::Values ::RESERVED_BANK_CODES )
9+ end
10+ end
11+ end
12+ end
Original file line number Diff line number Diff line change 22
33module MT9
44 module Validators
5- class HeaderRecordContract < Dry ::Validation ::Contract
6- RESERVED_BANK_CODES = %w[ 99 ] . freeze
7-
8- DIRECT_CREDIT = "12"
9- DIRECT_DEBIT = "20"
10- FILE_TYPES = [ DIRECT_CREDIT , DIRECT_DEBIT ] . freeze
11-
5+ class HeaderRecordContract < BaseContract
126 schema do
13- required ( :file_type ) . filled ( :string , included_in? : FILE_TYPES )
7+ required ( :file_type ) . filled ( :string , included_in? : MT9 :: Values :: FILE_TYPES )
148 required ( :account_number ) . filled ( :string )
159 required ( :due_date ) . filled ( :string )
1610 optional ( :client_short_name ) . value ( :string , size? : 0 ..20 )
1711 end
1812
19- rule ( :account_number ) do
20- key . failure ( "must be 15 or 16 numeric characters" ) unless /^(\d {15}|\d {16})$/ . match ( value )
21- key . failure ( "must not start with a reserved bank code" ) if value . start_with? ( *RESERVED_BANK_CODES )
22- end
13+ rule ( :account_number ) . validate ( :is_account_number? )
2314
2415 rule ( :due_date ) do
2516 key . failure ( "must be 6 or 8 numeric characters" ) unless /^(\d {6}|\d {8})$/ . match ( value )
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module MT9
4+ module Values
5+ RESERVED_BANK_CODES = %w[ 99 ] . freeze
6+
7+ DIRECT_CREDIT = "12"
8+ DIRECT_DEBIT = "20"
9+ FILE_TYPES = [ DIRECT_CREDIT , DIRECT_DEBIT ] . freeze
10+ end
11+ end
You can’t perform that action at this time.
0 commit comments