|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module MT9 |
| 4 | + class HeaderRecord < BaseRecord |
| 5 | + set_line_ending Fixy::Record::LINE_ENDING_CRLF |
| 6 | + |
| 7 | + attr_reader :file_type, :account_number, :due_date, :client_short_name |
| 8 | + |
| 9 | + field :file_type, 2, "1-2", :alphanumeric |
| 10 | + field :account_number, 16, "3-18", :alphanumeric |
| 11 | + field :due_date, 8, "19-26", :alphanumeric |
| 12 | + field :filler5, 5, "27-31", :alphanumeric |
| 13 | + field :client_short_name, 20, "32-51", :alphanumeric |
| 14 | + field :filler109, 109, "52-160", :alphanumeric |
| 15 | + |
| 16 | + field_value :filler5, SPACE * 5 |
| 17 | + field_value :filler109, SPACE * 109 |
| 18 | + |
| 19 | + def initialize(...) |
| 20 | + validator = Validators::HeaderRecordContract.new |
| 21 | + result = validator.call(...) |
| 22 | + raise MT9::ValidationError, result unless result.success? |
| 23 | + |
| 24 | + result.to_h.each do |key, value| |
| 25 | + instance_variable_set("@#{key}", value) |
| 26 | + end |
| 27 | + end |
| 28 | + end |
| 29 | +end |
0 commit comments