diff --git a/.gitignore b/.gitignore index fedcd85a..913631c6 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ test/fuzz-reader/corpus/*.tar.gz /cmd/webui/assets/wire.wasm # GoLand -/.idea/* \ No newline at end of file +/.idea/* + +# Gitleaks +gitleaks.tar.gz \ No newline at end of file diff --git a/accountCreditedDrawdown.go b/accountCreditedDrawdown.go index 87e3ee24..f8f4c53b 100644 --- a/accountCreditedDrawdown.go +++ b/accountCreditedDrawdown.go @@ -71,12 +71,19 @@ func (creditDD *AccountCreditedDrawdown) UnmarshalJSON(data []byte) error { return nil } -// String writes AccountCreditedDrawdown -func (creditDD *AccountCreditedDrawdown) String(options ...bool) string { +// String returns a fixed-width AccountCreditedDrawdown record +func (creditDD *AccountCreditedDrawdown) String() string { + return creditDD.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns an AccountCreditedDrawdown record formatted according to the FormatOptions +func (creditDD *AccountCreditedDrawdown) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(15) buf.WriteString(creditDD.tag) - buf.WriteString(creditDD.DrawdownCreditAccountNumberField(options...)) + buf.WriteString(creditDD.FormatCreditAccountNumber(options)) return buf.String() } @@ -105,6 +112,11 @@ func (creditDD *AccountCreditedDrawdown) fieldInclusion() error { } // DrawdownCreditAccountNumberField gets a string of the DrawdownCreditAccountNumber field -func (creditDD *AccountCreditedDrawdown) DrawdownCreditAccountNumberField(options ...bool) string { - return creditDD.alphaVariableField(creditDD.DrawdownCreditAccountNumber, 9, creditDD.parseFirstOption(options)) +func (creditDD *AccountCreditedDrawdown) DrawdownCreditAccountNumberField() string { + return creditDD.alphaField(creditDD.DrawdownCreditAccountNumber, 9) +} + +// FormatCreditAccountNumber returns DrawdownCreditAccountNumber formatted according to the FormatOptions +func (creditDD *AccountCreditedDrawdown) FormatCreditAccountNumber(options FormatOptions) string { + return creditDD.formatAlphaField(creditDD.DrawdownCreditAccountNumber, 9, options) } diff --git a/accountCreditedDrawdown_test.go b/accountCreditedDrawdown_test.go index 29cb4a15..4dd19806 100644 --- a/accountCreditedDrawdown_test.go +++ b/accountCreditedDrawdown_test.go @@ -112,7 +112,7 @@ func TestStringAccountCreditedDrawdownVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringAccountCreditedDrawdownOptions validates string() with options +// TestStringAccountCreditedDrawdownOptions validates Format() formatted according to the FormatOptions func TestStringAccountCreditedDrawdownOptions(t *testing.T) { var line = "{5400}1*" r := NewReader(strings.NewReader(line)) @@ -121,9 +121,8 @@ func TestStringAccountCreditedDrawdownOptions(t *testing.T) { err := r.parseAccountCreditedDrawdown() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.AccountCreditedDrawdown.String() - require.Equal(t, str, "{5400}1 ") - - str = r.currentFEDWireMessage.AccountCreditedDrawdown.String(true) - require.Equal(t, str, "{5400}1*") + acd := r.currentFEDWireMessage.AccountCreditedDrawdown + require.Equal(t, acd.String(), "{5400}1 ") + require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1*") + require.Equal(t, acd.String(), acd.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/accountDebitedDrawdown.go b/accountDebitedDrawdown.go index 77fe8a73..34f48c8b 100644 --- a/accountDebitedDrawdown.go +++ b/accountDebitedDrawdown.go @@ -105,20 +105,27 @@ func (debitDD *AccountDebitedDrawdown) UnmarshalJSON(data []byte) error { return nil } -// String writes AccountDebitedDrawdown -func (debitDD *AccountDebitedDrawdown) String(options ...bool) string { +// String returns a fixed-width AccountDebitedDrawdown record +func (debitDD *AccountDebitedDrawdown) String() string { + return debitDD.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns an AccountDebitedDrawdown record formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(debitDD.tag) buf.WriteString(debitDD.IdentificationCodeField()) - buf.WriteString(debitDD.IdentifierField(options...)) - buf.WriteString(debitDD.NameField(options...)) - buf.WriteString(debitDD.AddressLineOneField(options...)) - buf.WriteString(debitDD.AddressLineTwoField(options...)) - buf.WriteString(debitDD.AddressLineThreeField(options...)) + buf.WriteString(debitDD.FormatIdentifier(options)) + buf.WriteString(debitDD.FormatName(options)) + buf.WriteString(debitDD.FormatAddressLineOne(options)) + buf.WriteString(debitDD.FormatAddressLineTwo(options)) + buf.WriteString(debitDD.FormatAddressLineThree(options)) - if debitDD.parseFirstOption(options) { + if options.VariableLengthFields { return debitDD.stripDelimiters(buf.String()) } else { return buf.String() @@ -183,26 +190,51 @@ func (debitDD *AccountDebitedDrawdown) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (debitDD *AccountDebitedDrawdown) IdentifierField(options ...bool) string { - return debitDD.alphaVariableField(debitDD.Identifier, 34, debitDD.parseFirstOption(options)) +func (debitDD *AccountDebitedDrawdown) IdentifierField() string { + return debitDD.alphaField(debitDD.Identifier, 34) } // NameField gets a string of the Name field -func (debitDD *AccountDebitedDrawdown) NameField(options ...bool) string { - return debitDD.alphaVariableField(debitDD.Name, 35, debitDD.parseFirstOption(options)) +func (debitDD *AccountDebitedDrawdown) NameField() string { + return debitDD.alphaField(debitDD.Name, 35) +} + +// AddressLineOneField gets a string of Address.AddressLineOne field +func (debitDD *AccountDebitedDrawdown) AddressLineOneField() string { + return debitDD.alphaField(debitDD.Address.AddressLineOne, 35) +} + +// AddressLineTwoField gets a string of Address.AddressLineTwo field +func (debitDD *AccountDebitedDrawdown) AddressLineTwoField() string { + return debitDD.alphaField(debitDD.Address.AddressLineTwo, 35) +} + +// AddressLineThreeField gets a string of Address.AddressLineThree field +func (debitDD *AccountDebitedDrawdown) AddressLineThreeField() string { + return debitDD.alphaField(debitDD.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns Identifier formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) FormatIdentifier(options FormatOptions) string { + return debitDD.formatAlphaField(debitDD.Identifier, 34, options) +} + +// FormatName returns Name formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) FormatName(options FormatOptions) string { + return debitDD.formatAlphaField(debitDD.Name, 35, options) } -// AddressLineOneField gets a string of AddressLineOne field -func (debitDD *AccountDebitedDrawdown) AddressLineOneField(options ...bool) string { - return debitDD.alphaVariableField(debitDD.Address.AddressLineOne, 35, debitDD.parseFirstOption(options)) +// FormatAddressLineOne returns Address.AddressLineOne formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) FormatAddressLineOne(options FormatOptions) string { + return debitDD.formatAlphaField(debitDD.Address.AddressLineOne, 35, options) } -// AddressLineTwoField gets a string of AddressLineTwo field -func (debitDD *AccountDebitedDrawdown) AddressLineTwoField(options ...bool) string { - return debitDD.alphaVariableField(debitDD.Address.AddressLineTwo, 35, debitDD.parseFirstOption(options)) +// FormatAddressLineTwo returns Address.AddressLineTwo formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) FormatAddressLineTwo(options FormatOptions) string { + return debitDD.formatAlphaField(debitDD.Address.AddressLineTwo, 35, options) } -// AddressLineThreeField gets a string of AddressLineThree field -func (debitDD *AccountDebitedDrawdown) AddressLineThreeField(options ...bool) string { - return debitDD.alphaVariableField(debitDD.Address.AddressLineThree, 35, debitDD.parseFirstOption(options)) +// FormatAddressLineThree returns Address.AddressLineThree formatted according to the FormatOptions +func (debitDD *AccountDebitedDrawdown) FormatAddressLineThree(options FormatOptions) string { + return debitDD.formatAlphaField(debitDD.Address.AddressLineThree, 35, options) } diff --git a/accountDebitedDrawdown_test.go b/accountDebitedDrawdown_test.go index 5275e20a..aabf6422 100644 --- a/accountDebitedDrawdown_test.go +++ b/accountDebitedDrawdown_test.go @@ -197,7 +197,7 @@ func TestStringAccountDebitedDrawdownVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringDebitedDrawdownOptions validates string() with options +// TestStringDebitedDrawdownOptions validates Format() formatted according to the FormatOptions func TestStringAccountDebitedDrawdownOptions(t *testing.T) { var line = "{4400}D2*3*" r := NewReader(strings.NewReader(line)) @@ -206,9 +206,8 @@ func TestStringAccountDebitedDrawdownOptions(t *testing.T) { err := r.parseAccountDebitedDrawdown() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.AccountDebitedDrawdown.String() - require.Equal(t, str, "{4400}D2 3 ") - - str = r.currentFEDWireMessage.AccountDebitedDrawdown.String(true) - require.Equal(t, str, "{4400}D2*3*") + add := r.currentFEDWireMessage.AccountDebitedDrawdown + require.Equal(t, add.String(), "{4400}D2 3 ") + require.Equal(t, add.Format(FormatOptions{VariableLengthFields: true}), "{4400}D2*3*") + require.Equal(t, add.String(), add.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/actualAmountPaid.go b/actualAmountPaid.go index e94f3a76..765e2e11 100644 --- a/actualAmountPaid.go +++ b/actualAmountPaid.go @@ -78,14 +78,21 @@ func (aap *ActualAmountPaid) UnmarshalJSON(data []byte) error { return nil } -// String writes ActualAmountPaid -func (aap *ActualAmountPaid) String(options ...bool) string { +// String returns a fixed-width ActualAmountPaid record +func (aap *ActualAmountPaid) String() string { + return aap.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns an ActualAmountPaid record formatted according to the FormatOptions +func (aap *ActualAmountPaid) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(28) buf.WriteString(aap.tag) - buf.WriteString(aap.CurrencyCodeField(options...)) - buf.WriteString(aap.AmountField(options...)) + buf.WriteString(aap.FormatCurrencyCode(options)) + buf.WriteString(aap.FormatAmount(options)) return buf.String() } @@ -122,12 +129,22 @@ func (aap *ActualAmountPaid) fieldInclusion() error { return nil } -// CurrencyCodeField gets a string of the CurrencyCode field -func (aap *ActualAmountPaid) CurrencyCodeField(options ...bool) string { - return aap.alphaVariableField(aap.RemittanceAmount.CurrencyCode, 3, aap.parseFirstOption(options)) +// CurrencyCodeField gets a string of the RemittanceAmount.CurrencyCode field +func (aap *ActualAmountPaid) CurrencyCodeField() string { + return aap.alphaField(aap.RemittanceAmount.CurrencyCode, 3) +} + +// AmountField gets a string of the RemittanceAmount.Amount field +func (aap *ActualAmountPaid) AmountField() string { + return aap.alphaField(aap.RemittanceAmount.Amount, 19) +} + +// FormatCurrencyCode returns RemittanceAmount.CurrencyCode formatted according to the FormatOptions +func (aap *ActualAmountPaid) FormatCurrencyCode(options FormatOptions) string { + return aap.formatAlphaField(aap.RemittanceAmount.CurrencyCode, 3, options) } -// AmountField gets a string of the Amount field -func (aap *ActualAmountPaid) AmountField(options ...bool) string { - return aap.alphaVariableField(aap.RemittanceAmount.Amount, 19, aap.parseFirstOption(options)) +// FormatAmount returns RemittanceAmount.Amount formatted according to the FormatOptions +func (aap *ActualAmountPaid) FormatAmount(options FormatOptions) string { + return aap.formatAlphaField(aap.RemittanceAmount.Amount, 19, options) } diff --git a/actualAmountPaid_test.go b/actualAmountPaid_test.go index 8b55c34e..7f4992ce 100644 --- a/actualAmountPaid_test.go +++ b/actualAmountPaid_test.go @@ -140,7 +140,7 @@ func TestStringActualAmountPaidVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringActualAmountPaidOptions validates string() with options +// TestStringActualAmountPaidOptions validates Format() formatted according to the FormatOptions func TestStringActualAmountPaidOptions(t *testing.T) { var line = "{8450}USD1234.56*" r := NewReader(strings.NewReader(line)) @@ -149,9 +149,8 @@ func TestStringActualAmountPaidOptions(t *testing.T) { err := r.parseActualAmountPaid() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ActualAmountPaid.String() - require.Equal(t, str, "{8450}USD1234.56 ") - - str = r.currentFEDWireMessage.ActualAmountPaid.String(true) - require.Equal(t, str, "{8450}USD1234.56*") + aap := r.currentFEDWireMessage.ActualAmountPaid + require.Equal(t, aap.String(), "{8450}USD1234.56 ") + require.Equal(t, aap.Format(FormatOptions{VariableLengthFields: true}), "{8450}USD1234.56*") + require.Equal(t, aap.String(), aap.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/adjustment.go b/adjustment.go index 117f7494..01af64d1 100644 --- a/adjustment.go +++ b/adjustment.go @@ -105,19 +105,26 @@ func (adj *Adjustment) UnmarshalJSON(data []byte) error { return nil } -// String writes Adjustment -func (adj *Adjustment) String(options ...bool) string { +// String returns a fixed-width Adjustment record +func (adj *Adjustment) String() string { + return adj.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns an Adjustment record formatted according to the FormatOptions +func (adj *Adjustment) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(168) buf.WriteString(adj.tag) - buf.WriteString(adj.AdjustmentReasonCodeField(options...)) - buf.WriteString(adj.CreditDebitIndicatorField(options...)) - buf.WriteString(adj.CurrencyCodeField(options...)) - buf.WriteString(adj.AmountField(options...)) - buf.WriteString(adj.AdditionalInfoField(options...)) + buf.WriteString(adj.FormatAdjustmentReasonCode(options)) + buf.WriteString(adj.FormatCreditDebitIndicator(options)) + buf.WriteString(adj.FormatCurrencyCode(options)) + buf.WriteString(adj.FormatAmount(options)) + buf.WriteString(adj.FormatAdditionalInfo(options)) - if adj.parseFirstOption(options) { + if options.VariableLengthFields { return adj.stripDelimiters(buf.String()) } else { return buf.String() @@ -168,26 +175,51 @@ func (adj *Adjustment) fieldInclusion() error { } // AdjustmentReasonCodeField gets a string of the AdjustmentReasonCode field -func (adj *Adjustment) AdjustmentReasonCodeField(options ...bool) string { - return adj.alphaVariableField(adj.AdjustmentReasonCode, 2, adj.parseFirstOption(options)) +func (adj *Adjustment) AdjustmentReasonCodeField() string { + return adj.alphaField(adj.AdjustmentReasonCode, 2) } // CreditDebitIndicatorField gets a string of the CreditDebitIndicator field -func (adj *Adjustment) CreditDebitIndicatorField(options ...bool) string { - return adj.alphaVariableField(adj.CreditDebitIndicator, 4, adj.parseFirstOption(options)) +func (adj *Adjustment) CreditDebitIndicatorField() string { + return adj.alphaField(adj.CreditDebitIndicator, 4) } // CurrencyCodeField gets a string of the CurrencyCode field -func (adj *Adjustment) CurrencyCodeField(options ...bool) string { - return adj.alphaVariableField(adj.RemittanceAmount.CurrencyCode, 3, adj.parseFirstOption(options)) +func (adj *Adjustment) CurrencyCodeField() string { + return adj.alphaField(adj.RemittanceAmount.CurrencyCode, 3) } // AmountField gets a string of the Amount field -func (adj *Adjustment) AmountField(options ...bool) string { - return adj.alphaVariableField(adj.RemittanceAmount.Amount, 19, adj.parseFirstOption(options)) +func (adj *Adjustment) AmountField() string { + return adj.alphaField(adj.RemittanceAmount.Amount, 19) } // AdditionalInfoField gets a string of the AdditionalInfo field -func (adj *Adjustment) AdditionalInfoField(options ...bool) string { - return adj.alphaVariableField(adj.AdditionalInfo, 140, adj.parseFirstOption(options)) +func (adj *Adjustment) AdditionalInfoField() string { + return adj.alphaField(adj.AdditionalInfo, 140) +} + +// FormatAdjustmentReasonCode returns AdjustmentReasonCode formatted according to the FormatOptions +func (adj *Adjustment) FormatAdjustmentReasonCode(options FormatOptions) string { + return adj.formatAlphaField(adj.AdjustmentReasonCode, 2, options) +} + +// FormatCreditDebitIndicator returns CreditDebitIndicator formatted according to the FormatOptions +func (adj *Adjustment) FormatCreditDebitIndicator(options FormatOptions) string { + return adj.formatAlphaField(adj.CreditDebitIndicator, 4, options) +} + +// FormatCurrencyCode returns RemittanceAmount.CurrencyCode formatted according to the FormatOptions +func (adj *Adjustment) FormatCurrencyCode(options FormatOptions) string { + return adj.formatAlphaField(adj.RemittanceAmount.CurrencyCode, 3, options) +} + +// FormatAmount returns RemittanceAmount.Amount formatted according to the FormatOptions +func (adj *Adjustment) FormatAmount(options FormatOptions) string { + return adj.formatAlphaField(adj.RemittanceAmount.Amount, 19, options) +} + +// FormatAdditionalInfo returns AdditionalInfo formatted according to the FormatOptions +func (adj *Adjustment) FormatAdditionalInfo(options FormatOptions) string { + return adj.formatAlphaField(adj.AdditionalInfo, 140, options) } diff --git a/adjustment_test.go b/adjustment_test.go index 75397805..0f62bc1e 100644 --- a/adjustment_test.go +++ b/adjustment_test.go @@ -175,7 +175,7 @@ func TestStringAdjustmentVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringAdjustmentOptions validates string() with options +// TestStringAdjustmentOptions validates Format() formatted according to the FormatOptions func TestStringAdjustmentOptions(t *testing.T) { var line = "{8600}01CRDTUSD1234.56 *" r := NewReader(strings.NewReader(line)) @@ -184,9 +184,8 @@ func TestStringAdjustmentOptions(t *testing.T) { err := r.parseAdjustment() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.Adjustment.String() - require.Equal(t, str, "{8600}01CRDTUSD1234.56 ") - - str = r.currentFEDWireMessage.Adjustment.String(true) - require.Equal(t, str, "{8600}01CRDTUSD1234.56*") + adj := r.currentFEDWireMessage.Adjustment + require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 ") + require.Equal(t, adj.Format(FormatOptions{VariableLengthFields: true}), "{8600}01CRDTUSD1234.56*") + require.Equal(t, adj.String(), adj.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/amount.go b/amount.go index f34c17ed..578e7f01 100644 --- a/amount.go +++ b/amount.go @@ -58,7 +58,7 @@ func (a *Amount) UnmarshalJSON(data []byte) error { return nil } -// String writes Amount +// String returns a fixed-width Amount record func (a *Amount) String() string { var buf strings.Builder buf.Grow(18) diff --git a/amountNegotiatedDiscount.go b/amountNegotiatedDiscount.go index e71076a0..b7b208c0 100644 --- a/amountNegotiatedDiscount.go +++ b/amountNegotiatedDiscount.go @@ -78,14 +78,21 @@ func (nd *AmountNegotiatedDiscount) UnmarshalJSON(data []byte) error { return nil } -// String writes AmountNegotiatedDiscount -func (nd *AmountNegotiatedDiscount) String(options ...bool) string { +// String returns a fixed-width AmountNegotiatedDiscount record +func (nd *AmountNegotiatedDiscount) String() string { + return nd.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns an AmountNegotiatedDiscount record formatted according to the FormatOptions +func (nd *AmountNegotiatedDiscount) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(28) buf.WriteString(nd.tag) - buf.WriteString(nd.CurrencyCodeField(options...)) - buf.WriteString(nd.AmountField(options...)) + buf.WriteString(nd.FormatCurrencyCode(options)) + buf.WriteString(nd.FormatAmount(options)) return buf.String() } @@ -121,11 +128,21 @@ func (nd *AmountNegotiatedDiscount) fieldInclusion() error { } // CurrencyCodeField gets a string of the CurrencyCode field -func (nd *AmountNegotiatedDiscount) CurrencyCodeField(options ...bool) string { - return nd.alphaVariableField(nd.RemittanceAmount.CurrencyCode, 3, nd.parseFirstOption(options)) +func (nd *AmountNegotiatedDiscount) CurrencyCodeField() string { + return nd.alphaField(nd.RemittanceAmount.CurrencyCode, 3) } // AmountField gets a string of the Amount field -func (nd *AmountNegotiatedDiscount) AmountField(options ...bool) string { - return nd.alphaVariableField(nd.RemittanceAmount.Amount, 19, nd.parseFirstOption(options)) +func (nd *AmountNegotiatedDiscount) AmountField() string { + return nd.alphaField(nd.RemittanceAmount.Amount, 19) +} + +// FormatCurrencyCode returns RemittanceAmount.CurrencyCode formatted according to the FormatOptions +func (nd *AmountNegotiatedDiscount) FormatCurrencyCode(options FormatOptions) string { + return nd.formatAlphaField(nd.RemittanceAmount.CurrencyCode, 3, options) +} + +// FormatAmount returns RemittanceAmount.Amount formatted according to the FormatOptions +func (nd *AmountNegotiatedDiscount) FormatAmount(options FormatOptions) string { + return nd.formatAlphaField(nd.RemittanceAmount.Amount, 19, options) } diff --git a/amountNegotiatedDiscount_test.go b/amountNegotiatedDiscount_test.go index 47d643fd..8ce9bb15 100644 --- a/amountNegotiatedDiscount_test.go +++ b/amountNegotiatedDiscount_test.go @@ -132,7 +132,7 @@ func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringAmountNegotiatedDiscountOptions validates string() with options +// TestStringAmountNegotiatedDiscountOptions validates Format() formatted according to the FormatOptions func TestStringAmountNegotiatedDiscountOptions(t *testing.T) { var line = "{8550}USD1234.56*" r := NewReader(strings.NewReader(line)) @@ -141,9 +141,8 @@ func TestStringAmountNegotiatedDiscountOptions(t *testing.T) { err := r.parseAmountNegotiatedDiscount() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.AmountNegotiatedDiscount.String() - require.Equal(t, str, "{8550}USD1234.56 ") - - str = r.currentFEDWireMessage.AmountNegotiatedDiscount.String(true) - require.Equal(t, str, "{8550}USD1234.56*") + and := r.currentFEDWireMessage.AmountNegotiatedDiscount + require.Equal(t, and.String(), "{8550}USD1234.56 ") + require.Equal(t, and.Format(FormatOptions{VariableLengthFields: true}), "{8550}USD1234.56*") + require.Equal(t, and.String(), and.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiary.go b/beneficiary.go index 0d8e7a88..520ba305 100644 --- a/beneficiary.go +++ b/beneficiary.go @@ -100,20 +100,27 @@ func (ben *Beneficiary) UnmarshalJSON(data []byte) error { return nil } -// String writes Beneficiary -func (ben *Beneficiary) String(options ...bool) string { +// String returns a fixed-width Beneficiary record +func (ben *Beneficiary) String() string { + return ben.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a Beneficiary record formatted according to the FormatOptions +func (ben *Beneficiary) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(ben.tag) buf.WriteString(ben.IdentificationCodeField()) - buf.WriteString(ben.IdentifierField(options...)) - buf.WriteString(ben.NameField(options...)) - buf.WriteString(ben.AddressLineOneField(options...)) - buf.WriteString(ben.AddressLineTwoField(options...)) - buf.WriteString(ben.AddressLineThreeField(options...)) + buf.WriteString(ben.FormatIdentifier(options)) + buf.WriteString(ben.FormatName(options)) + buf.WriteString(ben.FormatAddressLineOne(options)) + buf.WriteString(ben.FormatAddressLineTwo(options)) + buf.WriteString(ben.FormatAddressLineThree(options)) - if ben.parseFirstOption(options) { + if options.VariableLengthFields { return ben.stripDelimiters(buf.String()) } else { return buf.String() @@ -170,26 +177,51 @@ func (ben *Beneficiary) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (ben *Beneficiary) IdentifierField(options ...bool) string { - return ben.alphaVariableField(ben.Personal.Identifier, 34, ben.parseFirstOption(options)) +func (ben *Beneficiary) IdentifierField() string { + return ben.alphaField(ben.Personal.Identifier, 34) } // NameField gets a string of the Name field -func (ben *Beneficiary) NameField(options ...bool) string { - return ben.alphaVariableField(ben.Personal.Name, 35, ben.parseFirstOption(options)) +func (ben *Beneficiary) NameField() string { + return ben.alphaField(ben.Personal.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (ben *Beneficiary) AddressLineOneField(options ...bool) string { - return ben.alphaVariableField(ben.Personal.Address.AddressLineOne, 35, ben.parseFirstOption(options)) +func (ben *Beneficiary) AddressLineOneField() string { + return ben.alphaField(ben.Personal.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (ben *Beneficiary) AddressLineTwoField(options ...bool) string { - return ben.alphaVariableField(ben.Personal.Address.AddressLineTwo, 35, ben.parseFirstOption(options)) +func (ben *Beneficiary) AddressLineTwoField() string { + return ben.alphaField(ben.Personal.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (ben *Beneficiary) AddressLineThreeField(options ...bool) string { - return ben.alphaVariableField(ben.Personal.Address.AddressLineThree, 35, ben.parseFirstOption(options)) +func (ben *Beneficiary) AddressLineThreeField() string { + return ben.alphaField(ben.Personal.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns Personal.Identifier formatted according to the FormatOptions +func (ben *Beneficiary) FormatIdentifier(options FormatOptions) string { + return ben.formatAlphaField(ben.Personal.Identifier, 34, options) +} + +// FormatName returns Personal.Name formatted according to the FormatOptions +func (ben *Beneficiary) FormatName(options FormatOptions) string { + return ben.formatAlphaField(ben.Personal.Name, 35, options) +} + +// FormatAddressLineOne returns Personal.Address.AddressLineOne formatted according to the FormatOptions +func (ben *Beneficiary) FormatAddressLineOne(options FormatOptions) string { + return ben.formatAlphaField(ben.Personal.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns Personal.Address.AddressLineTwo formatted according to the FormatOptions +func (ben *Beneficiary) FormatAddressLineTwo(options FormatOptions) string { + return ben.formatAlphaField(ben.Personal.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns Personal.Address.AddressLineThree formatted according to the FormatOptions +func (ben *Beneficiary) FormatAddressLineThree(options FormatOptions) string { + return ben.formatAlphaField(ben.Personal.Address.AddressLineThree, 35, options) } diff --git a/beneficiaryCustomer.go b/beneficiaryCustomer.go index 761e9e15..2838afd4 100644 --- a/beneficiaryCustomer.go +++ b/beneficiaryCustomer.go @@ -106,20 +106,27 @@ func (bc *BeneficiaryCustomer) UnmarshalJSON(data []byte) error { return nil } -// String writes BeneficiaryCustomer -func (bc *BeneficiaryCustomer) String(options ...bool) string { +// String returns a fixed-width BeneficiaryCustomer record +func (bc *BeneficiaryCustomer) String() string { + return bc.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a BeneficiaryCustomer record formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(186) buf.WriteString(bc.tag) - buf.WriteString(bc.SwiftFieldTagField(options...)) - buf.WriteString(bc.SwiftLineOneField(options...)) - buf.WriteString(bc.SwiftLineTwoField(options...)) - buf.WriteString(bc.SwiftLineThreeField(options...)) - buf.WriteString(bc.SwiftLineFourField(options...)) - buf.WriteString(bc.SwiftLineFiveField(options...)) - - if bc.parseFirstOption(options) { + buf.WriteString(bc.FormatSwiftFieldTag(options)) + buf.WriteString(bc.FormatSwiftLineOne(options)) + buf.WriteString(bc.FormatSwiftLineTwo(options)) + buf.WriteString(bc.FormatSwiftLineThree(options)) + buf.WriteString(bc.FormatSwiftLineFour(options)) + buf.WriteString(bc.FormatSwiftLineFive(options)) + + if options.VariableLengthFields { return bc.stripDelimiters(buf.String()) } else { return buf.String() @@ -166,31 +173,61 @@ func (bc *BeneficiaryCustomer) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (bc *BeneficiaryCustomer) SwiftFieldTagField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftFieldTag, 5, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftFieldTagField() string { + return bc.alphaField(bc.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (bc *BeneficiaryCustomer) SwiftLineOneField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftLineOne, 35, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftLineOneField() string { + return bc.alphaField(bc.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (bc *BeneficiaryCustomer) SwiftLineTwoField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftLineTwo, 35, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftLineTwoField() string { + return bc.alphaField(bc.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (bc *BeneficiaryCustomer) SwiftLineThreeField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftLineThree, 35, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftLineThreeField() string { + return bc.alphaField(bc.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (bc *BeneficiaryCustomer) SwiftLineFourField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftLineFour, 35, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftLineFourField() string { + return bc.alphaField(bc.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (bc *BeneficiaryCustomer) SwiftLineFiveField(options ...bool) string { - return bc.alphaVariableField(bc.CoverPayment.SwiftLineFive, 35, bc.parseFirstOption(options)) +func (bc *BeneficiaryCustomer) SwiftLineFiveField() string { + return bc.alphaField(bc.CoverPayment.SwiftLineFive, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftFieldTag(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftLineOne(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftLineTwo(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftLineThree(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftLineFour(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (bc *BeneficiaryCustomer) FormatSwiftLineFive(options FormatOptions) string { + return bc.formatAlphaField(bc.CoverPayment.SwiftLineFive, 35, options) } diff --git a/beneficiaryCustomer_test.go b/beneficiaryCustomer_test.go index 122fd2f4..02a9cea9 100644 --- a/beneficiaryCustomer_test.go +++ b/beneficiaryCustomer_test.go @@ -165,7 +165,7 @@ func TestStringBeneficiaryCustomerVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBeneficiaryCustomerOptions validates string() with options +// TestStringBeneficiaryCustomerOptions validates Format() formatted according to the FormatOptions func TestStringBeneficiaryCustomerOptions(t *testing.T) { var line = "{7059}*" r := NewReader(strings.NewReader(line)) @@ -174,9 +174,8 @@ func TestStringBeneficiaryCustomerOptions(t *testing.T) { err := r.parseBeneficiaryCustomer() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.BeneficiaryCustomer.String() - require.Equal(t, str, "{7059} ") - - str = r.currentFEDWireMessage.BeneficiaryCustomer.String(true) - require.Equal(t, str, "{7059}*") + bc := r.currentFEDWireMessage.BeneficiaryCustomer + require.Equal(t, bc.String(), "{7059} ") + require.Equal(t, bc.Format(FormatOptions{VariableLengthFields: true}), "{7059}*") + require.Equal(t, bc.String(), bc.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryFI.go b/beneficiaryFI.go index bbf4621b..3b9336b9 100644 --- a/beneficiaryFI.go +++ b/beneficiaryFI.go @@ -100,20 +100,27 @@ func (bfi *BeneficiaryFI) UnmarshalJSON(data []byte) error { return nil } -// String writes BeneficiaryFI -func (bfi *BeneficiaryFI) String(options ...bool) string { +// String returns a fixed-width BeneficiaryFI record +func (bfi *BeneficiaryFI) String() string { + return bfi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a BeneficiaryFI record formatted according to the FormatOptions +func (bfi *BeneficiaryFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(bfi.tag) buf.WriteString(bfi.IdentificationCodeField()) - buf.WriteString(bfi.IdentifierField(options...)) - buf.WriteString(bfi.NameField(options...)) - buf.WriteString(bfi.AddressLineOneField(options...)) - buf.WriteString(bfi.AddressLineTwoField(options...)) - buf.WriteString(bfi.AddressLineThreeField(options...)) + buf.WriteString(bfi.FormatIdentifier(options)) + buf.WriteString(bfi.FormatName(options)) + buf.WriteString(bfi.FormatAddressLineOne(options)) + buf.WriteString(bfi.FormatAddressLineTwo(options)) + buf.WriteString(bfi.FormatAddressLineThree(options)) - if bfi.parseFirstOption(options) { + if options.VariableLengthFields { return bfi.stripDelimiters(buf.String()) } else { return buf.String() @@ -179,26 +186,51 @@ func (bfi *BeneficiaryFI) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (bfi *BeneficiaryFI) IdentifierField(options ...bool) string { - return bfi.alphaVariableField(bfi.FinancialInstitution.Identifier, 34, bfi.parseFirstOption(options)) +func (bfi *BeneficiaryFI) IdentifierField() string { + return bfi.alphaField(bfi.FinancialInstitution.Identifier, 34) } // NameField gets a string of the Name field -func (bfi *BeneficiaryFI) NameField(options ...bool) string { - return bfi.alphaVariableField(bfi.FinancialInstitution.Name, 35, bfi.parseFirstOption(options)) +func (bfi *BeneficiaryFI) NameField() string { + return bfi.alphaField(bfi.FinancialInstitution.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (bfi *BeneficiaryFI) AddressLineOneField(options ...bool) string { - return bfi.alphaVariableField(bfi.FinancialInstitution.Address.AddressLineOne, 35, bfi.parseFirstOption(options)) +func (bfi *BeneficiaryFI) AddressLineOneField() string { + return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (bfi *BeneficiaryFI) AddressLineTwoField(options ...bool) string { - return bfi.alphaVariableField(bfi.FinancialInstitution.Address.AddressLineTwo, 35, bfi.parseFirstOption(options)) +func (bfi *BeneficiaryFI) AddressLineTwoField() string { + return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (bfi *BeneficiaryFI) AddressLineThreeField(options ...bool) string { - return bfi.alphaVariableField(bfi.FinancialInstitution.Address.AddressLineThree, 35, bfi.parseFirstOption(options)) +func (bfi *BeneficiaryFI) AddressLineThreeField() string { + return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns FinancialInstitution.Identifier formatted according to the FormatOptions +func (bfi *BeneficiaryFI) FormatIdentifier(options FormatOptions) string { + return bfi.formatAlphaField(bfi.FinancialInstitution.Identifier, 34, options) +} + +// FormatName returns FinancialInstitution.Name formatted according to the FormatOptions +func (bfi *BeneficiaryFI) FormatName(options FormatOptions) string { + return bfi.formatAlphaField(bfi.FinancialInstitution.Name, 35, options) +} + +// FormatAddressLineOne returns FinancialInstitution.Address.AddressLineOne formatted according to the FormatOptions +func (bfi *BeneficiaryFI) FormatAddressLineOne(options FormatOptions) string { + return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns FinancialInstitution.Address.AddressLineTwo formatted according to the FormatOptions +func (bfi *BeneficiaryFI) FormatAddressLineTwo(options FormatOptions) string { + return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns FinancialInstitution.Address.AddressLineThree formatted according to the FormatOptions +func (bfi *BeneficiaryFI) FormatAddressLineThree(options FormatOptions) string { + return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineThree, 35, options) } diff --git a/beneficiaryFI_test.go b/beneficiaryFI_test.go index 132d036d..e881a592 100644 --- a/beneficiaryFI_test.go +++ b/beneficiaryFI_test.go @@ -186,7 +186,7 @@ func TestStringBeneficiaryFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBeneficiaryFIOptions validates string() with options +// TestStringBeneficiaryFIOptions validates Format() formatted according to the FormatOptions func TestStringBeneficiaryFIOptions(t *testing.T) { var line = "{4100}D123456789*" r := NewReader(strings.NewReader(line)) @@ -195,9 +195,8 @@ func TestStringBeneficiaryFIOptions(t *testing.T) { err := r.parseBeneficiaryFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.BeneficiaryFI.String() - require.Equal(t, str, "{4100}D123456789 ") - - str = r.currentFEDWireMessage.BeneficiaryFI.String(true) - require.Equal(t, str, "{4100}D123456789*") + bfi := r.currentFEDWireMessage.BeneficiaryFI + require.Equal(t, bfi.String(), "{4100}D123456789 ") + require.Equal(t, bfi.Format(FormatOptions{VariableLengthFields: true}), "{4100}D123456789*") + require.Equal(t, bfi.String(), bfi.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index 74bab998..f827a74d 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -100,20 +100,27 @@ func (bifi *BeneficiaryIntermediaryFI) UnmarshalJSON(data []byte) error { return nil } -// String writes BeneficiaryIntermediaryFI -func (bifi *BeneficiaryIntermediaryFI) String(options ...bool) string { +// String returns a fixed-width BeneficiaryIntermediaryFI record +func (bifi *BeneficiaryIntermediaryFI) String() string { + return bifi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a BeneficiaryIntermediaryFI record formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(bifi.tag) buf.WriteString(bifi.IdentificationCodeField()) - buf.WriteString(bifi.IdentifierField(options...)) - buf.WriteString(bifi.NameField(options...)) - buf.WriteString(bifi.AddressLineOneField(options...)) - buf.WriteString(bifi.AddressLineTwoField(options...)) - buf.WriteString(bifi.AddressLineThreeField(options...)) + buf.WriteString(bifi.FormatIdentifier(options)) + buf.WriteString(bifi.FormatName(options)) + buf.WriteString(bifi.FormatAddressLineOne(options)) + buf.WriteString(bifi.FormatAddressLineTwo(options)) + buf.WriteString(bifi.FormatAddressLineThree(options)) - if bifi.parseFirstOption(options) { + if options.VariableLengthFields { return bifi.stripDelimiters(buf.String()) } else { return buf.String() @@ -176,26 +183,51 @@ func (bifi *BeneficiaryIntermediaryFI) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (bifi *BeneficiaryIntermediaryFI) IdentifierField(options ...bool) string { - return bifi.alphaVariableField(bifi.FinancialInstitution.Identifier, 34, bifi.parseFirstOption(options)) +func (bifi *BeneficiaryIntermediaryFI) IdentifierField() string { + return bifi.alphaField(bifi.FinancialInstitution.Identifier, 34) } // NameField gets a string of the Name field -func (bifi *BeneficiaryIntermediaryFI) NameField(options ...bool) string { - return bifi.alphaVariableField(bifi.FinancialInstitution.Name, 35, bifi.parseFirstOption(options)) +func (bifi *BeneficiaryIntermediaryFI) NameField() string { + return bifi.alphaField(bifi.FinancialInstitution.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (bifi *BeneficiaryIntermediaryFI) AddressLineOneField(options ...bool) string { - return bifi.alphaVariableField(bifi.FinancialInstitution.Address.AddressLineOne, 35, bifi.parseFirstOption(options)) +func (bifi *BeneficiaryIntermediaryFI) AddressLineOneField() string { + return bifi.alphaField(bifi.FinancialInstitution.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (bifi *BeneficiaryIntermediaryFI) AddressLineTwoField(options ...bool) string { - return bifi.alphaVariableField(bifi.FinancialInstitution.Address.AddressLineTwo, 35, bifi.parseFirstOption(options)) +func (bifi *BeneficiaryIntermediaryFI) AddressLineTwoField() string { + return bifi.alphaField(bifi.FinancialInstitution.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (bifi *BeneficiaryIntermediaryFI) AddressLineThreeField(options ...bool) string { - return bifi.alphaVariableField(bifi.FinancialInstitution.Address.AddressLineThree, 35, bifi.parseFirstOption(options)) +func (bifi *BeneficiaryIntermediaryFI) AddressLineThreeField() string { + return bifi.alphaField(bifi.FinancialInstitution.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns FinancialInstitution.Identifier formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) FormatIdentifier(options FormatOptions) string { + return bifi.formatAlphaField(bifi.FinancialInstitution.Identifier, 34, options) +} + +// FormatName returns FinancialInstitution.Name formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) FormatName(options FormatOptions) string { + return bifi.formatAlphaField(bifi.FinancialInstitution.Name, 35, options) +} + +// FormatAddressLineOne returns FinancialInstitution.Address.AddressLineOne formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) FormatAddressLineOne(options FormatOptions) string { + return bifi.formatAlphaField(bifi.FinancialInstitution.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns FinancialInstitution.Address.AddressLineTwo formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) FormatAddressLineTwo(options FormatOptions) string { + return bifi.formatAlphaField(bifi.FinancialInstitution.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns FinancialInstitution.Address.AddressLineThree formatted according to the FormatOptions +func (bifi *BeneficiaryIntermediaryFI) FormatAddressLineThree(options FormatOptions) string { + return bifi.formatAlphaField(bifi.FinancialInstitution.Address.AddressLineThree, 35, options) } diff --git a/beneficiaryIntermediaryFI_test.go b/beneficiaryIntermediaryFI_test.go index 94171db5..6bba6e27 100644 --- a/beneficiaryIntermediaryFI_test.go +++ b/beneficiaryIntermediaryFI_test.go @@ -189,7 +189,7 @@ func TestStringBeneficiaryIntermediaryFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBeneficiaryIntermediaryFIOptions validates string() with options +// TestStringBeneficiaryIntermediaryFIOptions validates Format() formatted according to the FormatOptions func TestStringBeneficiaryIntermediaryFIOptions(t *testing.T) { var line = "{4000}D123456789*" r := NewReader(strings.NewReader(line)) @@ -198,9 +198,8 @@ func TestStringBeneficiaryIntermediaryFIOptions(t *testing.T) { err := r.parseBeneficiaryIntermediaryFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.BeneficiaryIntermediaryFI.String() - require.Equal(t, str, "{4000}D123456789 ") - - str = r.currentFEDWireMessage.BeneficiaryIntermediaryFI.String(true) - require.Equal(t, str, "{4000}D123456789*") + bifi := r.currentFEDWireMessage.BeneficiaryIntermediaryFI + require.Equal(t, bifi.String(), "{4000}D123456789 ") + require.Equal(t, bifi.Format(FormatOptions{VariableLengthFields: true}), "{4000}D123456789*") + require.Equal(t, bifi.String(), bifi.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryReference.go b/beneficiaryReference.go index c58757af..fc4b4997 100644 --- a/beneficiaryReference.go +++ b/beneficiaryReference.go @@ -71,13 +71,20 @@ func (br *BeneficiaryReference) UnmarshalJSON(data []byte) error { return nil } -// String writes BeneficiaryReference -func (br *BeneficiaryReference) String(options ...bool) string { +// String returns a fixed-width BeneficiaryReference record +func (br *BeneficiaryReference) String() string { + return br.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a BeneficiaryReference record formatted according to the FormatOptions +func (br *BeneficiaryReference) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(22) buf.WriteString(br.tag) - buf.WriteString(br.BeneficiaryReferenceField(options...)) + buf.WriteString(br.FormatBeneficiaryReference(options)) return buf.String() } @@ -95,6 +102,11 @@ func (br *BeneficiaryReference) Validate() error { } // BeneficiaryReferenceField gets a string of the BeneficiaryReference field -func (br *BeneficiaryReference) BeneficiaryReferenceField(options ...bool) string { - return br.alphaVariableField(br.BeneficiaryReference, 16, br.parseFirstOption(options)) +func (br *BeneficiaryReference) BeneficiaryReferenceField() string { + return br.alphaField(br.BeneficiaryReference, 16) +} + +// FormatBeneficiaryReference returns BeneficiaryReference formatted according to the FormatOptions +func (br *BeneficiaryReference) FormatBeneficiaryReference(options FormatOptions) string { + return br.formatAlphaField(br.BeneficiaryReference, 16, options) } diff --git a/beneficiaryReference_test.go b/beneficiaryReference_test.go index f3f293c3..dac9550f 100644 --- a/beneficiaryReference_test.go +++ b/beneficiaryReference_test.go @@ -100,7 +100,7 @@ func TestStringBeneficiaryReferenceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBeneficiaryReferenceOptions validates string() with options +// TestStringBeneficiaryReferenceOptions validates Format() formatted according to the FormatOptions func TestStringBeneficiaryReferenceOptions(t *testing.T) { var line = "{4320}Reference*" r := NewReader(strings.NewReader(line)) @@ -109,9 +109,8 @@ func TestStringBeneficiaryReferenceOptions(t *testing.T) { err := r.parseBeneficiaryReference() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.BeneficiaryReference.String() - require.Equal(t, str, "{4320}Reference ") - - str = r.currentFEDWireMessage.BeneficiaryReference.String(true) - require.Equal(t, str, "{4320}Reference*") + br := r.currentFEDWireMessage.BeneficiaryReference + require.Equal(t, br.String(), "{4320}Reference ") + require.Equal(t, br.Format(FormatOptions{VariableLengthFields: true}), "{4320}Reference*") + require.Equal(t, br.String(), br.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiary_test.go b/beneficiary_test.go index a43153fd..2d892e0f 100644 --- a/beneficiary_test.go +++ b/beneficiary_test.go @@ -176,7 +176,7 @@ func TestStringBeneficiaryVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBeneficiaryOptions validates string() with options +// TestStringBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringBeneficiaryOptions(t *testing.T) { var line = "{4200}31234*" r := NewReader(strings.NewReader(line)) @@ -185,9 +185,8 @@ func TestStringBeneficiaryOptions(t *testing.T) { err := r.parseBeneficiary() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.Beneficiary.String() - require.Equal(t, str, "{4200}31234 ") - - str = r.currentFEDWireMessage.Beneficiary.String(true) - require.Equal(t, str, "{4200}31234*") + ben := r.currentFEDWireMessage.Beneficiary + require.Equal(t, ben.String(), "{4200}31234 ") + require.Equal(t, ben.Format(FormatOptions{VariableLengthFields: true}), "{4200}31234*") + require.Equal(t, ben.String(), ben.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/businessFunctionCode.go b/businessFunctionCode.go index 106d5985..1438c050 100644 --- a/businessFunctionCode.go +++ b/businessFunctionCode.go @@ -74,14 +74,21 @@ func (bfc *BusinessFunctionCode) UnmarshalJSON(data []byte) error { return nil } -// String writes BusinessFunctionCode -func (bfc *BusinessFunctionCode) String(options ...bool) string { +// String returns a fixed-width BusinessFunctionCode record +func (bfc *BusinessFunctionCode) String() string { + return bfc.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a BusinessFunctionCode record formatted according to the FormatOptions +func (bfc *BusinessFunctionCode) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(12) buf.WriteString(bfc.tag) buf.WriteString(bfc.BusinessFunctionCodeField()) - buf.WriteString(bfc.TransactionTypeCodeField(options...)) + buf.WriteString(bfc.FormatTransactionTypeCode(options)) return buf.String() } @@ -121,6 +128,11 @@ func (bfc *BusinessFunctionCode) BusinessFunctionCodeField() string { } // TransactionTypeCodeField gets a string of the TransactionTypeCode field -func (bfc *BusinessFunctionCode) TransactionTypeCodeField(options ...bool) string { - return bfc.alphaVariableField(bfc.TransactionTypeCode, 3, bfc.parseFirstOption(options)) +func (bfc *BusinessFunctionCode) TransactionTypeCodeField() string { + return bfc.alphaField(bfc.TransactionTypeCode, 3) +} + +// FormatTransactionTypeCode returns TransactionTypeCode formatted according to the FormatOptions +func (bfc *BusinessFunctionCode) FormatTransactionTypeCode(options FormatOptions) string { + return bfc.formatAlphaField(bfc.TransactionTypeCode, 3, options) } diff --git a/businessFunctionCode_test.go b/businessFunctionCode_test.go index 8b150c5b..4182b20f 100644 --- a/businessFunctionCode_test.go +++ b/businessFunctionCode_test.go @@ -112,7 +112,7 @@ func TestStringBusinessFunctionCodeVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringBusinessFunctionCodeOptions validates string() with options +// TestStringBusinessFunctionCodeOptions validates Format() formatted according to the FormatOptions func TestStringBusinessFunctionCodeOptions(t *testing.T) { var line = "{3600}BTR*" r := NewReader(strings.NewReader(line)) @@ -121,9 +121,9 @@ func TestStringBusinessFunctionCodeOptions(t *testing.T) { err := r.parseBusinessFunctionCode() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.BusinessFunctionCode.String() - require.Equal(t, str, "{3600}BTR ") + bfc := r.currentFEDWireMessage.BusinessFunctionCode + require.Equal(t, bfc.String(), "{3600}BTR ") + require.Equal(t, bfc.Format(FormatOptions{VariableLengthFields: true}), "{3600}BTR*") + require.Equal(t, bfc.String(), bfc.Format(FormatOptions{VariableLengthFields: false})) - str = r.currentFEDWireMessage.BusinessFunctionCode.String(true) - require.Equal(t, str, "{3600}BTR*") } diff --git a/charges.go b/charges.go index 4c9c84fd..3097dba0 100644 --- a/charges.go +++ b/charges.go @@ -109,19 +109,26 @@ func (c *Charges) UnmarshalJSON(data []byte) error { return nil } -// String writes Charges -func (c *Charges) String(options ...bool) string { +// String returns a fixed-width Charges record +func (c *Charges) String() string { + return c.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a Charges record formatted according to the FormatOptions +func (c *Charges) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(67) buf.WriteString(c.tag) buf.WriteString(c.ChargeDetailsField()) - buf.WriteString(c.SendersChargesOneField(options...)) - buf.WriteString(c.SendersChargesTwoField(options...)) - buf.WriteString(c.SendersChargesThreeField(options...)) - buf.WriteString(c.SendersChargesFourField(options...)) + buf.WriteString(c.FormatSendersChargesOne(options)) + buf.WriteString(c.FormatSendersChargesTwo(options)) + buf.WriteString(c.FormatSendersChargesThree(options)) + buf.WriteString(c.FormatSendersChargesFour(options)) - if c.parseFirstOption(options) { + if options.VariableLengthFields { return c.stripDelimiters(buf.String()) } else { return buf.String() @@ -176,21 +183,41 @@ func (c *Charges) ChargeDetailsField() string { } // SendersChargesOneField gets a string of the SendersChargesOne field -func (c *Charges) SendersChargesOneField(options ...bool) string { - return c.alphaVariableField(c.SendersChargesOne, 15, c.parseFirstOption(options)) +func (c *Charges) SendersChargesOneField() string { + return c.alphaField(c.SendersChargesOne, 15) } // SendersChargesTwoField gets a string of the SendersChargesTwo field -func (c *Charges) SendersChargesTwoField(options ...bool) string { - return c.alphaVariableField(c.SendersChargesTwo, 15, c.parseFirstOption(options)) +func (c *Charges) SendersChargesTwoField() string { + return c.alphaField(c.SendersChargesTwo, 15) } // SendersChargesThreeField gets a string of the SendersChargesThree field -func (c *Charges) SendersChargesThreeField(options ...bool) string { - return c.alphaVariableField(c.SendersChargesThree, 15, c.parseFirstOption(options)) +func (c *Charges) SendersChargesThreeField() string { + return c.alphaField(c.SendersChargesThree, 15) } // SendersChargesFourField gets a string of the SendersChargesFour field -func (c *Charges) SendersChargesFourField(options ...bool) string { - return c.alphaVariableField(c.SendersChargesFour, 15, c.parseFirstOption(options)) +func (c *Charges) SendersChargesFourField() string { + return c.alphaField(c.SendersChargesFour, 15) +} + +// FormatSendersChargesOne returns SendersChargesOne formatted according to the FormatOptions +func (c *Charges) FormatSendersChargesOne(options FormatOptions) string { + return c.formatAlphaField(c.SendersChargesOne, 15, options) +} + +// FormatSendersChargesTwo returns SendersChargesTwo formatted according to the FormatOptions +func (c *Charges) FormatSendersChargesTwo(options FormatOptions) string { + return c.formatAlphaField(c.SendersChargesTwo, 15, options) +} + +// FormatSendersChargesThree returns SendersChargesThree formatted according to the FormatOptions +func (c *Charges) FormatSendersChargesThree(options FormatOptions) string { + return c.formatAlphaField(c.SendersChargesThree, 15, options) +} + +// FormatSendersChargesFour returns SendersChargesFour formatted according to the FormatOptions +func (c *Charges) FormatSendersChargesFour(options FormatOptions) string { + return c.formatAlphaField(c.SendersChargesFour, 15, options) } diff --git a/charges_test.go b/charges_test.go index e4cabdff..2abf1477 100644 --- a/charges_test.go +++ b/charges_test.go @@ -75,7 +75,7 @@ func TestStringChargesVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringChargesOptions validates string() with options +// TestStringChargesOptions validates Format() formatted according to the FormatOptions func TestStringChargesOptions(t *testing.T) { var line = "{3700}B*" r := NewReader(strings.NewReader(line)) @@ -84,9 +84,8 @@ func TestStringChargesOptions(t *testing.T) { err := r.parseCharges() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.Charges.String() - require.Equal(t, str, "{3700}B ") - - str = r.currentFEDWireMessage.Charges.String(true) - require.Equal(t, str, "{3700}B*") + record := r.currentFEDWireMessage.Charges + require.Equal(t, record.String(), "{3700}B ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3700}B*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/converters.go b/converters.go index 2814a5c9..1489353e 100644 --- a/converters.go +++ b/converters.go @@ -22,16 +22,6 @@ func (c *converters) parseStringField(r string) (s string) { return s } -// alphaField Alphanumeric and Alphabetic fields are left-justified and space filled. -func (c *converters) alphaField(s string, max uint) string { - ln := uint(len(s)) - if ln > max { - return s[:max] - } - s += strings.Repeat(" ", int(max-ln)) - return s -} - // numericStringField right-justified zero filled func (c *converters) numericStringField(s string, max uint) string { ln := uint(len(s)) @@ -42,14 +32,22 @@ func (c *converters) numericStringField(s string, max uint) string { return s } -// alphaVariableField Alphanumeric and Alphabetic fields are left-justified and space filled. -func (c *converters) alphaVariableField(s string, max uint, isVariable bool) string { +// alphaField returns the input formatted as a fixed-width alphanumeric string. +// If the length of s exceeds max, s will be truncated to max. +func (c *converters) alphaField(s string, max uint) string { + return c.formatAlphaField(s, max, FormatOptions{}) +} + +// formatAlphaField returns the input formatted according to the FormatOptions. +// If the length of s exceeds max, s will be truncated to max. If options.VariableLengthFields +// is set, any trailing whitespace is replaced with a single asterisk (*) character. +func (c *converters) formatAlphaField(s string, max uint, options FormatOptions) string { ln := uint(len(s)) if ln > max { return s[:max] } - if isVariable { + if options.VariableLengthFields { if max-ln > 0 { s += "*" } diff --git a/converters_test.go b/converters_test.go index 03a3f50b..86e6a018 100644 --- a/converters_test.go +++ b/converters_test.go @@ -61,11 +61,46 @@ func TestConverters__parseVariableStringField(t *testing.T) { require.Nil(t, err) } -func TestConverters__alphaVariableField(t *testing.T) { +func TestConverters_alphaVariableField(t *testing.T) { + tests := []struct { + input string + variableLength bool + maxLength uint + want string + }{ + { + input: "{0000}1234 ", + variableLength: false, + maxLength: 10, + want: "{0000}1234", + }, + { + input: "{0000}1234 ", + variableLength: true, + maxLength: 10, + want: "{0000}1234", + }, + { + input: "{0000}12", + variableLength: false, + maxLength: 10, + want: "{0000}12 ", + }, + { + input: "{0000}12", + variableLength: true, + maxLength: 10, + want: "{0000}12*", + }, + } c := &converters{} - require.Equal(t, "{0000}1234", c.alphaVariableField("{0000}1234 ", 10, false)) - require.Equal(t, "{0000}1234", c.alphaVariableField("{0000}1234 ", 10, true)) - require.Equal(t, "{0000}12 ", c.alphaVariableField("{0000}12", 10, false)) - require.Equal(t, "{0000}12*", c.alphaVariableField("{0000}12", 10, true)) + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + opts := FormatOptions{ + VariableLengthFields: tt.variableLength, + } + require.Equal(t, tt.want, c.formatAlphaField(tt.input, tt.maxLength, opts)) + }) + } } diff --git a/currencyInstructedAmount.go b/currencyInstructedAmount.go index b7afa453..644f0f63 100644 --- a/currencyInstructedAmount.go +++ b/currencyInstructedAmount.go @@ -17,7 +17,7 @@ type CurrencyInstructedAmount struct { // SwiftFieldTag SwiftFieldTag string `json:"swiftFieldTag"` // Amount is the instructed amount - // Amount Must begin with at least one numeric character (0-9) and contain only one decimal comma marker + // Amount Must begin with at least one numeric character (0-9) and contain only one decimal comma marker // (e.g., $1,234.56 should be entered as 1234,56 and $0.99 should be entered as Amount string `json:"amount"` // validator is composed for data validation @@ -81,13 +81,20 @@ func (cia *CurrencyInstructedAmount) UnmarshalJSON(data []byte) error { return nil } -// String writes CurrencyInstructedAmount -func (cia *CurrencyInstructedAmount) String(options ...bool) string { +// String returns a fixed-width CurrencyInstructedAmount record +func (cia *CurrencyInstructedAmount) String() string { + return cia.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a CurrencyInstructedAmount record formatted according to the FormatOptions +func (cia *CurrencyInstructedAmount) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(29) buf.WriteString(cia.tag) - buf.WriteString(cia.SwiftFieldTagField(options...)) + buf.WriteString(cia.FormatSwiftFieldTag(options)) buf.WriteString(cia.AmountField()) return buf.String() @@ -109,8 +116,8 @@ func (cia *CurrencyInstructedAmount) Validate() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (cia *CurrencyInstructedAmount) SwiftFieldTagField(options ...bool) string { - return cia.alphaVariableField(cia.SwiftFieldTag, 5, cia.parseFirstOption(options)) +func (cia *CurrencyInstructedAmount) SwiftFieldTagField() string { + return cia.alphaField(cia.SwiftFieldTag, 5) } // ToDo: The spec isn't clear if this is padded with zeros or not, so for now it is @@ -119,3 +126,8 @@ func (cia *CurrencyInstructedAmount) SwiftFieldTagField(options ...bool) string func (cia *CurrencyInstructedAmount) AmountField() string { return cia.numericStringField(cia.Amount, 18) } + +// FormatSwiftFieldTag returns SwiftFieldTag formatted according to the FormatOptions +func (cia *CurrencyInstructedAmount) FormatSwiftFieldTag(options FormatOptions) string { + return cia.formatAlphaField(cia.SwiftFieldTag, 5, options) +} diff --git a/currencyInstructedAmount_test.go b/currencyInstructedAmount_test.go index e7a398a2..6e2fe8ee 100644 --- a/currencyInstructedAmount_test.go +++ b/currencyInstructedAmount_test.go @@ -99,7 +99,7 @@ func TestStringCurrencyInstructedAmountVariableLength(t *testing.T) { require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) } -// TestStringCurrencyInstructedAmountOptions validates string() with options +// TestStringCurrencyInstructedAmountOptions validates Format() formatted according to the FormatOptions func TestStringCurrencyInstructedAmountOptions(t *testing.T) { var line = "{7033}*000000000001500,49" r := NewReader(strings.NewReader(line)) @@ -108,9 +108,8 @@ func TestStringCurrencyInstructedAmountOptions(t *testing.T) { err := r.parseCurrencyInstructedAmount() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.CurrencyInstructedAmount.String() - require.Equal(t, str, "{7033} 000000000001500,49") - - str = r.currentFEDWireMessage.CurrencyInstructedAmount.String(true) - require.Equal(t, str, "{7033}*000000000001500,49") + record := r.currentFEDWireMessage.CurrencyInstructedAmount + require.Equal(t, record.String(), "{7033} 000000000001500,49") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7033}*000000000001500,49") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/errorWire.go b/errorWire.go index 78c57b8b..45c22081 100644 --- a/errorWire.go +++ b/errorWire.go @@ -89,17 +89,24 @@ func (ew *ErrorWire) UnmarshalJSON(data []byte) error { return nil } -// String writes ErrorWire -func (ew *ErrorWire) String(options ...bool) string { +// String returns a fixed-width ErrorWire record +func (ew *ErrorWire) String() string { + return ew.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a ErrorWire record formatted according to the FormatOptions +func (ew *ErrorWire) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(45) buf.WriteString(ew.tag) - buf.WriteString(ew.ErrorCategoryField(options...)) - buf.WriteString(ew.ErrorCodeField(options...)) - buf.WriteString(ew.ErrorDescriptionField(options...)) + buf.WriteString(ew.FormatErrorCategory(options)) + buf.WriteString(ew.FormatErrorCode(options)) + buf.WriteString(ew.FormatErrorDescription(options)) - if ew.parseFirstOption(options) { + if options.VariableLengthFields { return ew.stripDelimiters(buf.String()) } else { return buf.String() @@ -114,16 +121,31 @@ func (ew *ErrorWire) Validate() error { } // ErrorCategoryField gets a string of the ErrorCategory field -func (ew *ErrorWire) ErrorCategoryField(options ...bool) string { - return ew.alphaVariableField(ew.ErrorCategory, 1, ew.parseFirstOption(options)) +func (ew *ErrorWire) ErrorCategoryField() string { + return ew.alphaField(ew.ErrorCategory, 1) } // ErrorCodeField gets a string of the ErrorCode field -func (ew *ErrorWire) ErrorCodeField(options ...bool) string { - return ew.alphaVariableField(ew.ErrorCode, 3, ew.parseFirstOption(options)) +func (ew *ErrorWire) ErrorCodeField() string { + return ew.alphaField(ew.ErrorCode, 3) } // ErrorDescriptionField gets a string of the ErrorDescription field -func (ew *ErrorWire) ErrorDescriptionField(options ...bool) string { - return ew.alphaVariableField(ew.ErrorDescription, 35, ew.parseFirstOption(options)) +func (ew *ErrorWire) ErrorDescriptionField() string { + return ew.alphaField(ew.ErrorDescription, 35) +} + +// FormatErrorCategory returns ErrorCategory formatted according to the FormatOptions +func (ew *ErrorWire) FormatErrorCategory(options FormatOptions) string { + return ew.formatAlphaField(ew.ErrorCategory, 1, options) +} + +// FormatErrorCode returns ErrorCode formatted according to the FormatOptions +func (ew *ErrorWire) FormatErrorCode(options FormatOptions) string { + return ew.formatAlphaField(ew.ErrorCode, 3, options) +} + +// FormatErrorDescription returns ErrorDescription formatted according to the FormatOptions +func (ew *ErrorWire) FormatErrorDescription(options FormatOptions) string { + return ew.formatAlphaField(ew.ErrorDescription, 35, options) } diff --git a/errorWire_test.go b/errorWire_test.go index 45ec979d..ba00047d 100644 --- a/errorWire_test.go +++ b/errorWire_test.go @@ -80,7 +80,7 @@ func TestStringErrorWireAmountVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringErrorWireOptions validates string() with options +// TestStringErrorWireOptions validates Format() formatted according to the FormatOptions func TestStringErrorWireOptions(t *testing.T) { var line = "{1130}1XYZData Error*" r := NewReader(strings.NewReader(line)) @@ -89,9 +89,8 @@ func TestStringErrorWireOptions(t *testing.T) { err := r.parseErrorWire() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ErrorWire.String() - require.Equal(t, str, "{1130}1XYZData Error ") - - str = r.currentFEDWireMessage.ErrorWire.String(true) - require.Equal(t, str, "{1130}1XYZData Error*") + record := r.currentFEDWireMessage.ErrorWire + require.Equal(t, record.String(), "{1130}1XYZData Error ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1130}1XYZData Error*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/exchangeRate.go b/exchangeRate.go index 0bbd0a31..84197ae3 100644 --- a/exchangeRate.go +++ b/exchangeRate.go @@ -72,15 +72,22 @@ func (eRate *ExchangeRate) UnmarshalJSON(data []byte) error { return nil } -// String writes ExchangeRate -func (eRate *ExchangeRate) String(options ...bool) string { +// String returns a fixed-width ExchangeRate record +func (eRate *ExchangeRate) String() string { + return eRate.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a ExchangeRate record formatted according to the FormatOptions +func (eRate *ExchangeRate) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(18) buf.WriteString(eRate.tag) - buf.WriteString(eRate.ExchangeRateField(options...)) + buf.WriteString(eRate.FormatExchangeRate(options)) - if eRate.parseFirstOption(options) { + if options.VariableLengthFields { return eRate.stripDelimiters(buf.String()) } else { return buf.String() @@ -100,6 +107,11 @@ func (eRate *ExchangeRate) Validate() error { } // ExchangeRateField gets a string of the ExchangeRate field -func (eRate *ExchangeRate) ExchangeRateField(options ...bool) string { - return eRate.alphaVariableField(eRate.ExchangeRate, 12, eRate.parseFirstOption(options)) +func (eRate *ExchangeRate) ExchangeRateField() string { + return eRate.alphaField(eRate.ExchangeRate, 12) +} + +// FormatExchangeRate returns ExchangeRate formatted according to the FormatOptions +func (eRate *ExchangeRate) FormatExchangeRate(options FormatOptions) string { + return eRate.formatAlphaField(eRate.ExchangeRate, 12, options) } diff --git a/exchangeRate_test.go b/exchangeRate_test.go index 51ed88ec..198c1f27 100644 --- a/exchangeRate_test.go +++ b/exchangeRate_test.go @@ -102,7 +102,7 @@ func TestStringErrorExchangeRateVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringExchangeRateOptions validates string() with options +// TestStringExchangeRateOptions validates Format() formatted according to the FormatOptions func TestStringExchangeRateOptions(t *testing.T) { var line = "{3720}123*" r := NewReader(strings.NewReader(line)) @@ -111,9 +111,8 @@ func TestStringExchangeRateOptions(t *testing.T) { err := r.parseExchangeRate() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ExchangeRate.String() - require.Equal(t, str, "{3720}123 ") - - str = r.currentFEDWireMessage.ExchangeRate.String(true) - require.Equal(t, str, "{3720}123*") + record := r.currentFEDWireMessage.ExchangeRate + require.Equal(t, record.String(), "{3720}123 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3720}123*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fIBeneficiaryFIAdvice.go b/fIBeneficiaryFIAdvice.go index f4d84fd5..30d7d89f 100644 --- a/fIBeneficiaryFIAdvice.go +++ b/fIBeneficiaryFIAdvice.go @@ -107,21 +107,28 @@ func (fibfia *FIBeneficiaryFIAdvice) UnmarshalJSON(data []byte) error { return nil } -// String writes FIBeneficiaryFIAdvice -func (fibfia *FIBeneficiaryFIAdvice) String(options ...bool) string { +// String returns a fixed-width FIBeneficiaryFIAdvice record +func (fibfia *FIBeneficiaryFIAdvice) String() string { + return fibfia.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIBeneficiaryFIAdvice record formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(200) buf.WriteString(fibfia.tag) buf.WriteString(fibfia.AdviceCodeField()) - buf.WriteString(fibfia.LineOneField(options...)) - buf.WriteString(fibfia.LineTwoField(options...)) - buf.WriteString(fibfia.LineThreeField(options...)) - buf.WriteString(fibfia.LineFourField(options...)) - buf.WriteString(fibfia.LineFiveField(options...)) - buf.WriteString(fibfia.LineSixField(options...)) - - if fibfia.parseFirstOption(options) { + buf.WriteString(fibfia.FormatLineOne(options)) + buf.WriteString(fibfia.FormatLineTwo(options)) + buf.WriteString(fibfia.FormatLineThree(options)) + buf.WriteString(fibfia.FormatLineFour(options)) + buf.WriteString(fibfia.FormatLineFive(options)) + buf.WriteString(fibfia.FormatLineSix(options)) + + if options.VariableLengthFields { return fibfia.stripDelimiters(buf.String()) } else { return buf.String() @@ -164,31 +171,61 @@ func (fibfia *FIBeneficiaryFIAdvice) AdviceCodeField() string { } // LineOneField gets a string of the LineOne field -func (fibfia *FIBeneficiaryFIAdvice) LineOneField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineOne, 26, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineOneField() string { + return fibfia.alphaField(fibfia.Advice.LineOne, 26) } // LineTwoField gets a string of the LineTwo field -func (fibfia *FIBeneficiaryFIAdvice) LineTwoField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineTwo, 33, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineTwoField() string { + return fibfia.alphaField(fibfia.Advice.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fibfia *FIBeneficiaryFIAdvice) LineThreeField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineThree, 33, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineThreeField() string { + return fibfia.alphaField(fibfia.Advice.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fibfia *FIBeneficiaryFIAdvice) LineFourField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineFour, 33, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineFourField() string { + return fibfia.alphaField(fibfia.Advice.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fibfia *FIBeneficiaryFIAdvice) LineFiveField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineFive, 33, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineFiveField() string { + return fibfia.alphaField(fibfia.Advice.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fibfia *FIBeneficiaryFIAdvice) LineSixField(options ...bool) string { - return fibfia.alphaVariableField(fibfia.Advice.LineSix, 33, fibfia.parseFirstOption(options)) +func (fibfia *FIBeneficiaryFIAdvice) LineSixField() string { + return fibfia.alphaField(fibfia.Advice.LineSix, 33) +} + +// FormatLineOne returns Advice.LineOne formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineOne(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineOne, 26, options) +} + +// FormatLineTwo returns Advice.LineTwo formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineTwo(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineTwo, 33, options) +} + +// FormatLineThree returns Advice.LineThree formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineThree(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineThree, 33, options) +} + +// FormatLineFour returns Advice.LineFour formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineFour(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineFour, 33, options) +} + +// FormatLineFive returns Advice.LineFive formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineFive(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineFive, 33, options) +} + +// FormatLineSix returns Advice.LineSix formatted according to the FormatOptions +func (fibfia *FIBeneficiaryFIAdvice) FormatLineSix(options FormatOptions) string { + return fibfia.formatAlphaField(fibfia.Advice.LineSix, 33, options) } diff --git a/fIBeneficiaryFIAdvice_test.go b/fIBeneficiaryFIAdvice_test.go index ad068f86..667da391 100644 --- a/fIBeneficiaryFIAdvice_test.go +++ b/fIBeneficiaryFIAdvice_test.go @@ -166,7 +166,7 @@ func TestStringFIBeneficiaryFIAdviceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIBeneficiaryFIAdviceOptions validates string() with options +// TestStringFIBeneficiaryFIAdviceOptions validates Format() formatted according to the FormatOptions func TestStringFIBeneficiaryFIAdviceOptions(t *testing.T) { var line = "{6310}HLD*" r := NewReader(strings.NewReader(line)) @@ -175,9 +175,8 @@ func TestStringFIBeneficiaryFIAdviceOptions(t *testing.T) { err := r.parseFIBeneficiaryFIAdvice() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIBeneficiaryFIAdvice.String() - require.Equal(t, str, "{6310}HLD ") - - str = r.currentFEDWireMessage.FIBeneficiaryFIAdvice.String(true) - require.Equal(t, str, "{6310}HLD*") + record := r.currentFEDWireMessage.FIBeneficiaryFIAdvice + require.Equal(t, record.String(), "{6310}HLD ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6310}HLD*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiAdditionalFIToFI.go b/fiAdditionalFIToFI.go index 803ea6b0..1e0ded88 100644 --- a/fiAdditionalFIToFI.go +++ b/fiAdditionalFIToFI.go @@ -106,20 +106,27 @@ func (fifi *FIAdditionalFIToFI) UnmarshalJSON(data []byte) error { return nil } -// String writes FIAdditionalFIToFI -func (fifi *FIAdditionalFIToFI) String(options ...bool) string { +// String returns a fixed-width FIAdditionalFIToFI record +func (fifi *FIAdditionalFIToFI) String() string { + return fifi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIAdditionalFIToFI record formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(216) buf.WriteString(fifi.tag) - buf.WriteString(fifi.LineOneField(options...)) - buf.WriteString(fifi.LineTwoField(options...)) - buf.WriteString(fifi.LineThreeField(options...)) - buf.WriteString(fifi.LineFourField(options...)) - buf.WriteString(fifi.LineFiveField(options...)) - buf.WriteString(fifi.LineSixField(options...)) - - if fifi.parseFirstOption(options) { + buf.WriteString(fifi.FormatLineOne(options)) + buf.WriteString(fifi.FormatLineTwo(options)) + buf.WriteString(fifi.FormatLineThree(options)) + buf.WriteString(fifi.FormatLineFour(options)) + buf.WriteString(fifi.FormatLineFive(options)) + buf.WriteString(fifi.FormatLineSix(options)) + + if options.VariableLengthFields { return fifi.stripDelimiters(buf.String()) } else { return buf.String() @@ -154,31 +161,61 @@ func (fifi *FIAdditionalFIToFI) Validate() error { } // LineOneField gets a string of the LineOne field -func (fifi *FIAdditionalFIToFI) LineOneField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineOne, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineOneField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineOne, 35) } // LineTwoField gets a string of the LineTwo field -func (fifi *FIAdditionalFIToFI) LineTwoField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineTwo, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineTwoField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineTwo, 35) } // LineThreeField gets a string of the LineThree field -func (fifi *FIAdditionalFIToFI) LineThreeField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineThree, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineThreeField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineThree, 35) } // LineFourField gets a string of the LineFour field -func (fifi *FIAdditionalFIToFI) LineFourField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineFour, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineFourField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineFour, 35) } // LineFiveField gets a string of the LineFive field -func (fifi *FIAdditionalFIToFI) LineFiveField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineFive, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineFiveField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineFive, 35) } // LineSixField gets a string of the LineSix field -func (fifi *FIAdditionalFIToFI) LineSixField(options ...bool) string { - return fifi.alphaVariableField(fifi.AdditionalFIToFI.LineSix, 35, fifi.parseFirstOption(options)) +func (fifi *FIAdditionalFIToFI) LineSixField() string { + return fifi.alphaField(fifi.AdditionalFIToFI.LineSix, 35) +} + +// FormatLineOne returns AdditionalFIToFI.LineOne formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineOne(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineOne, 35, options) +} + +// FormatLineTwo returns AdditionalFIToFI.LineTwo formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineTwo(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineTwo, 35, options) +} + +// FormatLineThree returns AdditionalFIToFI.LineThree formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineThree(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineThree, 35, options) +} + +// FormatLineFour returns AdditionalFIToFI.LineFour formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineFour(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineFour, 35, options) +} + +// FormatLineFive returns AdditionalFIToFI.LineFive formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineFive(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineFive, 35, options) +} + +// FormatLineSix returns AdditionalFIToFI.LineSix formatted according to the FormatOptions +func (fifi *FIAdditionalFIToFI) FormatLineSix(options FormatOptions) string { + return fifi.formatAlphaField(fifi.AdditionalFIToFI.LineSix, 35, options) } diff --git a/fiAdditionalFIToFI_test.go b/fiAdditionalFIToFI_test.go index cf7b07dc..f734f81e 100644 --- a/fiAdditionalFIToFI_test.go +++ b/fiAdditionalFIToFI_test.go @@ -154,7 +154,7 @@ func TestStringFIAdditionalFIToFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIAdditionalFIToFIOptions validates string() with options +// TestStringFIAdditionalFIToFIOptions validates Format() formatted according to the FormatOptions func TestStringFIAdditionalFIToFIOptions(t *testing.T) { var line = "{6500}*" r := NewReader(strings.NewReader(line)) @@ -163,9 +163,8 @@ func TestStringFIAdditionalFIToFIOptions(t *testing.T) { err := r.parseFIAdditionalFIToFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIAdditionalFIToFI.String() - require.Equal(t, str, "{6500} ") - - str = r.currentFEDWireMessage.FIAdditionalFIToFI.String(true) - require.Equal(t, str, "{6500}*") + record := r.currentFEDWireMessage.FIAdditionalFIToFI + require.Equal(t, record.String(), "{6500} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6500}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiary.go b/fiBeneficiary.go index 98c48b39..2bf5c934 100644 --- a/fiBeneficiary.go +++ b/fiBeneficiary.go @@ -106,20 +106,27 @@ func (fib *FIBeneficiary) UnmarshalJSON(data []byte) error { return nil } -// String writes FIBeneficiary -func (fib *FIBeneficiary) String(options ...bool) string { +// String returns a fixed-width FIBeneficiary record +func (fib *FIBeneficiary) String() string { + return fib.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIBeneficiary record formatted according to the FormatOptions +func (fib *FIBeneficiary) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(201) buf.WriteString(fib.tag) - buf.WriteString(fib.LineOneField(options...)) - buf.WriteString(fib.LineTwoField(options...)) - buf.WriteString(fib.LineThreeField(options...)) - buf.WriteString(fib.LineFourField(options...)) - buf.WriteString(fib.LineFiveField(options...)) - buf.WriteString(fib.LineSixField(options...)) + buf.WriteString(fib.FormatLineOne(options)) + buf.WriteString(fib.FormatLineTwo(options)) + buf.WriteString(fib.FormatLineThree(options)) + buf.WriteString(fib.FormatLineFour(options)) + buf.WriteString(fib.FormatLineFive(options)) + buf.WriteString(fib.FormatLineSix(options)) - if fib.parseFirstOption(options) { + if options.VariableLengthFields { return fib.stripDelimiters(buf.String()) } else { return buf.String() @@ -154,31 +161,61 @@ func (fib *FIBeneficiary) Validate() error { } // LineOneField gets a string of the LineOne field -func (fib *FIBeneficiary) LineOneField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineOne, 30, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineOneField() string { + return fib.alphaField(fib.FIToFI.LineOne, 30) } // LineTwoField gets a string of the LineTwo field -func (fib *FIBeneficiary) LineTwoField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineTwo, 33, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineTwoField() string { + return fib.alphaField(fib.FIToFI.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fib *FIBeneficiary) LineThreeField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineThree, 33, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineThreeField() string { + return fib.alphaField(fib.FIToFI.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fib *FIBeneficiary) LineFourField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineFour, 33, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineFourField() string { + return fib.alphaField(fib.FIToFI.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fib *FIBeneficiary) LineFiveField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineFive, 33, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineFiveField() string { + return fib.alphaField(fib.FIToFI.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fib *FIBeneficiary) LineSixField(options ...bool) string { - return fib.alphaVariableField(fib.FIToFI.LineSix, 33, fib.parseFirstOption(options)) +func (fib *FIBeneficiary) LineSixField() string { + return fib.alphaField(fib.FIToFI.LineSix, 33) +} + +// FormatLineOne returns FIToFI.LineOne formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineOne(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineOne, 30, options) +} + +// FormatLineTwo returns FIToFI.LineTwo formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineTwo(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineTwo, 33, options) +} + +// FormatLineThree returns FIToFI.LineThree formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineThree(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineThree, 33, options) +} + +// FormatLineFour returns FIToFI.LineFour formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineFour(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineFour, 33, options) +} + +// FormatLineFive returns FIToFI.LineFive formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineFive(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineFive, 33, options) +} + +// FormatLineSix returns FIToFI.LineSix formatted according to the FormatOptions +func (fib *FIBeneficiary) FormatLineSix(options FormatOptions) string { + return fib.formatAlphaField(fib.FIToFI.LineSix, 33, options) } diff --git a/fiBeneficiaryAdvice.go b/fiBeneficiaryAdvice.go index 25c444a1..86d0f8f1 100644 --- a/fiBeneficiaryAdvice.go +++ b/fiBeneficiaryAdvice.go @@ -107,21 +107,28 @@ func (fiba *FIBeneficiaryAdvice) UnmarshalJSON(data []byte) error { return nil } -// String writes FIBeneficiaryAdvice -func (fiba *FIBeneficiaryAdvice) String(options ...bool) string { +// String returns a fixed-width FIBeneficiaryAdvice record +func (fiba *FIBeneficiaryAdvice) String() string { + return fiba.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIBeneficiaryAdvice record formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(200) buf.WriteString(fiba.tag) buf.WriteString(fiba.AdviceCodeField()) - buf.WriteString(fiba.LineOneField(options...)) - buf.WriteString(fiba.LineTwoField(options...)) - buf.WriteString(fiba.LineThreeField(options...)) - buf.WriteString(fiba.LineFourField(options...)) - buf.WriteString(fiba.LineFiveField(options...)) - buf.WriteString(fiba.LineSixField(options...)) - - if fiba.parseFirstOption(options) { + buf.WriteString(fiba.FormatLineOne(options)) + buf.WriteString(fiba.FormatLineTwo(options)) + buf.WriteString(fiba.FormatLineThree(options)) + buf.WriteString(fiba.FormatLineFour(options)) + buf.WriteString(fiba.FormatLineFive(options)) + buf.WriteString(fiba.FormatLineSix(options)) + + if options.VariableLengthFields { return fiba.stripDelimiters(buf.String()) } else { return buf.String() @@ -164,31 +171,61 @@ func (fiba *FIBeneficiaryAdvice) AdviceCodeField() string { } // LineOneField gets a string of the LineOne field -func (fiba *FIBeneficiaryAdvice) LineOneField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineOne, 26, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineOneField() string { + return fiba.alphaField(fiba.Advice.LineOne, 26) } // LineTwoField gets a string of the LineTwo field -func (fiba *FIBeneficiaryAdvice) LineTwoField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineTwo, 33, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineTwoField() string { + return fiba.alphaField(fiba.Advice.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fiba *FIBeneficiaryAdvice) LineThreeField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineThree, 33, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineThreeField() string { + return fiba.alphaField(fiba.Advice.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fiba *FIBeneficiaryAdvice) LineFourField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineFour, 33, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineFourField() string { + return fiba.alphaField(fiba.Advice.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fiba *FIBeneficiaryAdvice) LineFiveField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineFive, 33, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineFiveField() string { + return fiba.alphaField(fiba.Advice.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fiba *FIBeneficiaryAdvice) LineSixField(options ...bool) string { - return fiba.alphaVariableField(fiba.Advice.LineSix, 33, fiba.parseFirstOption(options)) +func (fiba *FIBeneficiaryAdvice) LineSixField() string { + return fiba.alphaField(fiba.Advice.LineSix, 33) +} + +// FormatLineOne returns Advice.LineOne formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineOne(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineOne, 26, options) +} + +// FormatLineTwo returns Advice.LineTwo formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineTwo(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineTwo, 33, options) +} + +// FormatLineThree returns Advice.LineThree formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineThree(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineThree, 33, options) +} + +// FormatLineFour returns Advice.LineFour formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineFour(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineFour, 33, options) +} + +// FormatLineFive returns Advice.LineFive formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineFive(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineFive, 33, options) +} + +// FormatLineSix returns Advice.LineSix formatted according to the FormatOptions +func (fiba *FIBeneficiaryAdvice) FormatLineSix(options FormatOptions) string { + return fiba.formatAlphaField(fiba.Advice.LineSix, 33, options) } diff --git a/fiBeneficiaryAdvice_test.go b/fiBeneficiaryAdvice_test.go index e5eb8301..851443ea 100644 --- a/fiBeneficiaryAdvice_test.go +++ b/fiBeneficiaryAdvice_test.go @@ -157,7 +157,7 @@ func TestStringFIBeneficiaryAdviceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIBeneficiaryAdviceOptions validates string() with options +// TestStringFIBeneficiaryAdviceOptions validates Format() formatted according to the FormatOptions func TestStringFIBeneficiaryAdviceOptions(t *testing.T) { var line = "{6410}HLD*" r := NewReader(strings.NewReader(line)) @@ -166,9 +166,8 @@ func TestStringFIBeneficiaryAdviceOptions(t *testing.T) { err := r.parseFIBeneficiaryAdvice() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIBeneficiaryAdvice.String() - require.Equal(t, str, "{6410}HLD ") - - str = r.currentFEDWireMessage.FIBeneficiaryAdvice.String(true) - require.Equal(t, str, "{6410}HLD*") + record := r.currentFEDWireMessage.FIBeneficiaryAdvice + require.Equal(t, record.String(), "{6410}HLD ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6410}HLD*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiaryFI.go b/fiBeneficiaryFI.go index 78851bcf..01e7d509 100644 --- a/fiBeneficiaryFI.go +++ b/fiBeneficiaryFI.go @@ -106,20 +106,27 @@ func (fibfi *FIBeneficiaryFI) UnmarshalJSON(data []byte) error { return nil } -// String writes FIBeneficiaryFI -func (fibfi *FIBeneficiaryFI) String(options ...bool) string { +// String returns a fixed-width FIBeneficiaryFI record +func (fibfi *FIBeneficiaryFI) String() string { + return fibfi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIBeneficiaryFI record formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(201) buf.WriteString(fibfi.tag) - buf.WriteString(fibfi.LineOneField(options...)) - buf.WriteString(fibfi.LineTwoField(options...)) - buf.WriteString(fibfi.LineThreeField(options...)) - buf.WriteString(fibfi.LineFourField(options...)) - buf.WriteString(fibfi.LineFiveField(options...)) - buf.WriteString(fibfi.LineSixField(options...)) - - if fibfi.parseFirstOption(options) { + buf.WriteString(fibfi.FormatLineOne(options)) + buf.WriteString(fibfi.FormatLineTwo(options)) + buf.WriteString(fibfi.FormatLineThree(options)) + buf.WriteString(fibfi.FormatLineFour(options)) + buf.WriteString(fibfi.FormatLineFive(options)) + buf.WriteString(fibfi.FormatLineSix(options)) + + if options.VariableLengthFields { return fibfi.stripDelimiters(buf.String()) } else { return buf.String() @@ -154,31 +161,61 @@ func (fibfi *FIBeneficiaryFI) Validate() error { } // LineOneField gets a string of the LineOne field -func (fibfi *FIBeneficiaryFI) LineOneField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineOne, 30, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineOneField() string { + return fibfi.alphaField(fibfi.FIToFI.LineOne, 30) } // LineTwoField gets a string of the LineTwo field -func (fibfi *FIBeneficiaryFI) LineTwoField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineTwo, 33, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineTwoField() string { + return fibfi.alphaField(fibfi.FIToFI.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fibfi *FIBeneficiaryFI) LineThreeField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineThree, 33, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineThreeField() string { + return fibfi.alphaField(fibfi.FIToFI.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fibfi *FIBeneficiaryFI) LineFourField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineFour, 33, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineFourField() string { + return fibfi.alphaField(fibfi.FIToFI.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fibfi *FIBeneficiaryFI) LineFiveField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineFive, 33, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineFiveField() string { + return fibfi.alphaField(fibfi.FIToFI.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fibfi *FIBeneficiaryFI) LineSixField(options ...bool) string { - return fibfi.alphaVariableField(fibfi.FIToFI.LineSix, 33, fibfi.parseFirstOption(options)) +func (fibfi *FIBeneficiaryFI) LineSixField() string { + return fibfi.alphaField(fibfi.FIToFI.LineSix, 33) +} + +// FormatLineOne returns FIToFI.LineOne formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineOne(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineOne, 30, options) +} + +// FormatLineTwo returns FIToFI.LineTwo formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineTwo(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineTwo, 33, options) +} + +// FormatLineThree FIToFI.LineThree LineOne formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineThree(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineThree, 33, options) +} + +// FormatLineFour returns FIToFI.LineFour formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineFour(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineFour, 33, options) +} + +// FormatLineFive returns FIToFI.LineFive formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineFive(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineFive, 33, options) +} + +// FormatLineSix returns FIToFI.LineSix formatted according to the FormatOptions +func (fibfi *FIBeneficiaryFI) FormatLineSix(options FormatOptions) string { + return fibfi.formatAlphaField(fibfi.FIToFI.LineSix, 33, options) } diff --git a/fiBeneficiaryFI_test.go b/fiBeneficiaryFI_test.go index 8693164e..93c2d80b 100644 --- a/fiBeneficiaryFI_test.go +++ b/fiBeneficiaryFI_test.go @@ -155,7 +155,7 @@ func TestStringFIBeneficiaryFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIBeneficiaryFIToFIOptions validates string() with options +// TestStringFIBeneficiaryFIToFIOptions validates Format() formatted according to the FormatOptions func TestStringFIBeneficiaryFIToFIOptions(t *testing.T) { var line = "{6300}*" r := NewReader(strings.NewReader(line)) @@ -164,9 +164,8 @@ func TestStringFIBeneficiaryFIToFIOptions(t *testing.T) { err := r.parseFIBeneficiaryFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIBeneficiaryFI.String() - require.Equal(t, str, "{6300} ") - - str = r.currentFEDWireMessage.FIBeneficiaryFI.String(true) - require.Equal(t, str, "{6300}*") + record := r.currentFEDWireMessage.FIBeneficiaryFI + require.Equal(t, record.String(), "{6300} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6300}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiary_test.go b/fiBeneficiary_test.go index 4ddea90a..b525cf84 100644 --- a/fiBeneficiary_test.go +++ b/fiBeneficiary_test.go @@ -154,7 +154,7 @@ func TestStringFIBeneficiaryVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIBeneficiaryOptions validates string() with options +// TestStringFIBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringFIBeneficiaryOptions(t *testing.T) { var line = "{6400}*" r := NewReader(strings.NewReader(line)) @@ -163,9 +163,8 @@ func TestStringFIBeneficiaryOptions(t *testing.T) { err := r.parseFIBeneficiary() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIBeneficiary.String() - require.Equal(t, str, "{6400} ") - - str = r.currentFEDWireMessage.FIBeneficiary.String(true) - require.Equal(t, str, "{6400}*") + record := r.currentFEDWireMessage.FIBeneficiary + require.Equal(t, record.String(), "{6400} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6400}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiDrawdownDebitAccountAdvice.go b/fiDrawdownDebitAccountAdvice.go index c46d9358..2f528e71 100644 --- a/fiDrawdownDebitAccountAdvice.go +++ b/fiDrawdownDebitAccountAdvice.go @@ -107,21 +107,28 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) UnmarshalJSON(data []byte) er return nil } -// String writes FIDrawdownDebitAccountAdvice -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) String(options ...bool) string { +// String returns a fixed-width FIDrawdownDebitAccountAdvice record +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) String() string { + return debitDDAdvice.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIDrawdownDebitAccountAdvice record formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(200) buf.WriteString(debitDDAdvice.tag) buf.WriteString(debitDDAdvice.AdviceCodeField()) - buf.WriteString(debitDDAdvice.LineOneField(options...)) - buf.WriteString(debitDDAdvice.LineTwoField(options...)) - buf.WriteString(debitDDAdvice.LineThreeField(options...)) - buf.WriteString(debitDDAdvice.LineFourField(options...)) - buf.WriteString(debitDDAdvice.LineFiveField(options...)) - buf.WriteString(debitDDAdvice.LineSixField(options...)) - - if debitDDAdvice.parseFirstOption(options) { + buf.WriteString(debitDDAdvice.FormatLineOne(options)) + buf.WriteString(debitDDAdvice.FormatLineTwo(options)) + buf.WriteString(debitDDAdvice.FormatLineThree(options)) + buf.WriteString(debitDDAdvice.FormatLineFour(options)) + buf.WriteString(debitDDAdvice.FormatLineFive(options)) + buf.WriteString(debitDDAdvice.FormatLineSix(options)) + + if options.VariableLengthFields { return debitDDAdvice.stripDelimiters(buf.String()) } else { return buf.String() @@ -164,31 +171,61 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) AdviceCodeField() string { } // LineOneField gets a string of the LineOne field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineOneField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineOne, 26, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineOneField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineOne, 26) } // LineTwoField gets a string of the LineTwo field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineTwoField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineTwo, 33, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineTwoField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineThreeField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineThree, 33, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineThreeField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineFourField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineFour, 33, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineFourField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineFiveField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineFive, 33, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineFiveField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineSixField(options ...bool) string { - return debitDDAdvice.alphaVariableField(debitDDAdvice.Advice.LineSix, 33, debitDDAdvice.parseFirstOption(options)) +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) LineSixField() string { + return debitDDAdvice.alphaField(debitDDAdvice.Advice.LineSix, 33) +} + +// FormatLineOne returns Advice.LineOne formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineOne(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineOne, 26, options) +} + +// FormatLineTwo returns Advice.LineTwo formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineTwo(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineTwo, 33, options) +} + +// FormatLineThree returns Advice.LineThree formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineThree(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineThree, 33, options) +} + +// FormatLineFour returns Advice.LineFour formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineFour(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineFour, 33, options) +} + +// FormatLineFive returns Advice.LineFive formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineFive(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineFive, 33, options) +} + +// FormatLineSix returns Advice.LineSix formatted according to the FormatOptions +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) FormatLineSix(options FormatOptions) string { + return debitDDAdvice.formatAlphaField(debitDDAdvice.Advice.LineSix, 33, options) } diff --git a/fiDrawdownDebitAccountAdvice_test.go b/fiDrawdownDebitAccountAdvice_test.go index c2573d9d..bbe3a5e5 100644 --- a/fiDrawdownDebitAccountAdvice_test.go +++ b/fiDrawdownDebitAccountAdvice_test.go @@ -166,7 +166,7 @@ func TestStringFIDrawdownDebitAccountAdviceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIDrawdownDebitAccountAdviceOptions validates string() with options +// TestStringFIDrawdownDebitAccountAdviceOptions validates Format() formatted according to the FormatOptions func TestStringFIDrawdownDebitAccountAdviceOptions(t *testing.T) { var line = "{6110}HLD*" r := NewReader(strings.NewReader(line)) @@ -175,9 +175,8 @@ func TestStringFIDrawdownDebitAccountAdviceOptions(t *testing.T) { err := r.parseFIDrawdownDebitAccountAdvice() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIDrawdownDebitAccountAdvice.String() - require.Equal(t, str, "{6110}HLD ") - - str = r.currentFEDWireMessage.FIDrawdownDebitAccountAdvice.String(true) - require.Equal(t, str, "{6110}HLD*") + record := r.currentFEDWireMessage.FIDrawdownDebitAccountAdvice + require.Equal(t, record.String(), "{6110}HLD ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6110}HLD*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiIntermediaryFI.go b/fiIntermediaryFI.go index 46ac96e6..ab154f9e 100644 --- a/fiIntermediaryFI.go +++ b/fiIntermediaryFI.go @@ -106,20 +106,27 @@ func (fiifi *FIIntermediaryFI) UnmarshalJSON(data []byte) error { return nil } -// String writes FIIntermediaryFI -func (fiifi *FIIntermediaryFI) String(options ...bool) string { +// String returns a fixed-width FIIntermediaryFI record +func (fiifi *FIIntermediaryFI) String() string { + return fiifi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIIntermediaryFI record formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(201) buf.WriteString(fiifi.tag) - buf.WriteString(fiifi.LineOneField(options...)) - buf.WriteString(fiifi.LineTwoField(options...)) - buf.WriteString(fiifi.LineThreeField(options...)) - buf.WriteString(fiifi.LineFourField(options...)) - buf.WriteString(fiifi.LineFiveField(options...)) - buf.WriteString(fiifi.LineSixField(options...)) - - if fiifi.parseFirstOption(options) { + buf.WriteString(fiifi.FormatLineOne(options)) + buf.WriteString(fiifi.FormatLineTwo(options)) + buf.WriteString(fiifi.FormatLineThree(options)) + buf.WriteString(fiifi.FormatLineFour(options)) + buf.WriteString(fiifi.FormatLineFive(options)) + buf.WriteString(fiifi.FormatLineSix(options)) + + if options.VariableLengthFields { return fiifi.stripDelimiters(buf.String()) } else { return buf.String() @@ -154,31 +161,61 @@ func (fiifi *FIIntermediaryFI) Validate() error { } // LineOneField gets a string of the LineOne field -func (fiifi *FIIntermediaryFI) LineOneField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineOne, 30, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineOneField() string { + return fiifi.alphaField(fiifi.FIToFI.LineOne, 30) } // LineTwoField gets a string of the LineTwo field -func (fiifi *FIIntermediaryFI) LineTwoField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineTwo, 33, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineTwoField() string { + return fiifi.alphaField(fiifi.FIToFI.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fiifi *FIIntermediaryFI) LineThreeField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineThree, 33, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineThreeField() string { + return fiifi.alphaField(fiifi.FIToFI.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fiifi *FIIntermediaryFI) LineFourField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineFour, 33, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineFourField() string { + return fiifi.alphaField(fiifi.FIToFI.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fiifi *FIIntermediaryFI) LineFiveField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineFive, 33, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineFiveField() string { + return fiifi.alphaField(fiifi.FIToFI.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fiifi *FIIntermediaryFI) LineSixField(options ...bool) string { - return fiifi.alphaVariableField(fiifi.FIToFI.LineSix, 33, fiifi.parseFirstOption(options)) +func (fiifi *FIIntermediaryFI) LineSixField() string { + return fiifi.alphaField(fiifi.FIToFI.LineSix, 33) +} + +// FormatLineOne returns FIToFI.LineOne formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineOne(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineOne, 30, options) +} + +// FormatLineTwo returns FIToFI.LineTwo formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineTwo(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineTwo, 33, options) +} + +// FormatLineThree returns FIToFI.LineThree formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineThree(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineThree, 33, options) +} + +// FormatLineFour returns FIToFI.LineFour formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineFour(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineFour, 33, options) +} + +// FormatLineFive returns FIToFI.LineFive formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineFive(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineFive, 33, options) +} + +// FormatLineSix returns FIToFI.LineSix formatted according to the FormatOptions +func (fiifi *FIIntermediaryFI) FormatLineSix(options FormatOptions) string { + return fiifi.formatAlphaField(fiifi.FIToFI.LineSix, 33, options) } diff --git a/fiIntermediaryFIAdvice.go b/fiIntermediaryFIAdvice.go index d3093480..9395954d 100644 --- a/fiIntermediaryFIAdvice.go +++ b/fiIntermediaryFIAdvice.go @@ -107,21 +107,28 @@ func (fiifia *FIIntermediaryFIAdvice) UnmarshalJSON(data []byte) error { return nil } -// String writes FIIntermediaryFIAdvice -func (fiifia *FIIntermediaryFIAdvice) String(options ...bool) string { +// String returns a fixed-width FIIntermediaryFIAdvice record +func (fiifia *FIIntermediaryFIAdvice) String() string { + return fiifia.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIIntermediaryFIAdvice record formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(200) buf.WriteString(fiifia.tag) buf.WriteString(fiifia.AdviceCodeField()) - buf.WriteString(fiifia.LineOneField(options...)) - buf.WriteString(fiifia.LineTwoField(options...)) - buf.WriteString(fiifia.LineThreeField(options...)) - buf.WriteString(fiifia.LineFourField(options...)) - buf.WriteString(fiifia.LineFiveField(options...)) - buf.WriteString(fiifia.LineSixField(options...)) - - if fiifia.parseFirstOption(options) { + buf.WriteString(fiifia.FormatLineOne(options)) + buf.WriteString(fiifia.FormatLineTwo(options)) + buf.WriteString(fiifia.FormatLineThree(options)) + buf.WriteString(fiifia.FormatLineFour(options)) + buf.WriteString(fiifia.FormatLineFive(options)) + buf.WriteString(fiifia.FormatLineSix(options)) + + if options.VariableLengthFields { return fiifia.stripDelimiters(buf.String()) } else { return buf.String() @@ -164,31 +171,61 @@ func (fiifia *FIIntermediaryFIAdvice) AdviceCodeField() string { } // LineOneField gets a string of the LineOne field -func (fiifia *FIIntermediaryFIAdvice) LineOneField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineOne, 26, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineOneField() string { + return fiifia.alphaField(fiifia.Advice.LineOne, 26) } // LineTwoField gets a string of the LineTwo field -func (fiifia *FIIntermediaryFIAdvice) LineTwoField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineTwo, 33, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineTwoField() string { + return fiifia.alphaField(fiifia.Advice.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (fiifia *FIIntermediaryFIAdvice) LineThreeField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineThree, 33, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineThreeField() string { + return fiifia.alphaField(fiifia.Advice.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (fiifia *FIIntermediaryFIAdvice) LineFourField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineFour, 33, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineFourField() string { + return fiifia.alphaField(fiifia.Advice.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (fiifia *FIIntermediaryFIAdvice) LineFiveField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineFive, 33, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineFiveField() string { + return fiifia.alphaField(fiifia.Advice.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (fiifia *FIIntermediaryFIAdvice) LineSixField(options ...bool) string { - return fiifia.alphaVariableField(fiifia.Advice.LineSix, 33, fiifia.parseFirstOption(options)) +func (fiifia *FIIntermediaryFIAdvice) LineSixField() string { + return fiifia.alphaField(fiifia.Advice.LineSix, 33) +} + +// FormatLineOne returns Advice.LineOne formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineOne(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineOne, 26, options) +} + +// FormatLineTwo returns Advice.LineTwo formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineTwo(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineTwo, 33, options) +} + +// FormatLineThree returns Advice.LineThree formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineThree(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineThree, 33, options) +} + +// FormatLineFour returns Advice.LineFour formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineFour(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineFour, 33, options) +} + +// FormatLineFive returns Advice.LineFive formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineFive(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineFive, 33, options) +} + +// FormatLineSix returns Advice.LineSix formatted according to the FormatOptions +func (fiifia *FIIntermediaryFIAdvice) FormatLineSix(options FormatOptions) string { + return fiifia.formatAlphaField(fiifia.Advice.LineSix, 33, options) } diff --git a/fiIntermediaryFIAdvice_test.go b/fiIntermediaryFIAdvice_test.go index ca1770c9..5add769c 100644 --- a/fiIntermediaryFIAdvice_test.go +++ b/fiIntermediaryFIAdvice_test.go @@ -165,7 +165,7 @@ func TestStringFIIntermediaryFIAdviceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIIntermediaryFIAdviceOptions validates string() with options +// TestStringFIIntermediaryFIAdviceOptions validates Format() formatted according to the FormatOptions func TestStringFIIntermediaryFIAdviceOptions(t *testing.T) { var line = "{6210}HLD*" r := NewReader(strings.NewReader(line)) @@ -174,9 +174,8 @@ func TestStringFIIntermediaryFIAdviceOptions(t *testing.T) { err := r.parseFIIntermediaryFIAdvice() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIIntermediaryFIAdvice.String() - require.Equal(t, str, "{6210}HLD ") - - str = r.currentFEDWireMessage.FIIntermediaryFIAdvice.String(true) - require.Equal(t, str, "{6210}HLD*") + record := r.currentFEDWireMessage.FIIntermediaryFIAdvice + require.Equal(t, record.String(), "{6210}HLD ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6210}HLD*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiIntermediaryFI_test.go b/fiIntermediaryFI_test.go index 294f89dc..cfe29793 100644 --- a/fiIntermediaryFI_test.go +++ b/fiIntermediaryFI_test.go @@ -154,7 +154,7 @@ func TestStringFIIntermediaryFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIIntermediaryFIOptions validates string() with options +// TestStringFIIntermediaryFIOptions validates Format() formatted according to the FormatOptions func TestStringFIIntermediaryFIOptions(t *testing.T) { var line = "{6200}*" r := NewReader(strings.NewReader(line)) @@ -163,9 +163,8 @@ func TestStringFIIntermediaryFIOptions(t *testing.T) { err := r.parseFIIntermediaryFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIIntermediaryFI.String() - require.Equal(t, str, "{6200} ") - - str = r.currentFEDWireMessage.FIIntermediaryFI.String(true) - require.Equal(t, str, "{6200}*") + record := r.currentFEDWireMessage.FIIntermediaryFI + require.Equal(t, record.String(), "{6200} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6200}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiPaymentMethodToBeneficiary.go b/fiPaymentMethodToBeneficiary.go index ffb3c085..ec813605 100644 --- a/fiPaymentMethodToBeneficiary.go +++ b/fiPaymentMethodToBeneficiary.go @@ -75,14 +75,21 @@ func (pm *FIPaymentMethodToBeneficiary) UnmarshalJSON(data []byte) error { return nil } -// String writes FIPaymentMethodToBeneficiary -func (pm *FIPaymentMethodToBeneficiary) String(options ...bool) string { +// String returns a fixed-width FIPaymentMethodToBeneficiary record +func (pm *FIPaymentMethodToBeneficiary) String() string { + return pm.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIPaymentMethodToBeneficiary record formatted according to the FormatOptions +func (pm *FIPaymentMethodToBeneficiary) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(41) buf.WriteString(pm.tag) buf.WriteString(pm.PaymentMethodField()) - buf.WriteString(pm.AdditionalInformationField(options...)) + buf.WriteString(pm.FormatAdditionalInformation(options)) return buf.String() } @@ -117,6 +124,11 @@ func (pm *FIPaymentMethodToBeneficiary) PaymentMethodField() string { } // AdditionalInformationField gets a string of the AdditionalInformation field -func (pm *FIPaymentMethodToBeneficiary) AdditionalInformationField(options ...bool) string { - return pm.alphaVariableField(pm.AdditionalInformation, 30, pm.parseFirstOption(options)) +func (pm *FIPaymentMethodToBeneficiary) AdditionalInformationField() string { + return pm.alphaField(pm.AdditionalInformation, 30) +} + +// FormatAdditionalInformation returns AdditionalInformation formatted according to the FormatOptions +func (pm *FIPaymentMethodToBeneficiary) FormatAdditionalInformation(options FormatOptions) string { + return pm.formatAlphaField(pm.AdditionalInformation, 30, options) } diff --git a/fiPaymentMethodToBeneficiary_test.go b/fiPaymentMethodToBeneficiary_test.go index 86204acb..dfcf6b1b 100644 --- a/fiPaymentMethodToBeneficiary_test.go +++ b/fiPaymentMethodToBeneficiary_test.go @@ -110,7 +110,7 @@ func TestStringFIPaymentMethodToBeneficiaryVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIPaymentMethodToBeneficiaryOptions validates string() with options +// TestStringFIPaymentMethodToBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringFIPaymentMethodToBeneficiaryOptions(t *testing.T) { var line = "{6420}CHECK*" r := NewReader(strings.NewReader(line)) @@ -119,9 +119,8 @@ func TestStringFIPaymentMethodToBeneficiaryOptions(t *testing.T) { err := r.parseFIPaymentMethodToBeneficiary() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIPaymentMethodToBeneficiary.String() - require.Equal(t, str, "{6420}CHECK ") - - str = r.currentFEDWireMessage.FIPaymentMethodToBeneficiary.String(true) - require.Equal(t, str, "{6420}CHECK*") + record := r.currentFEDWireMessage.FIPaymentMethodToBeneficiary + require.Equal(t, record.String(), "{6420}CHECK ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6420}CHECK*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiReceiverFI.go b/fiReceiverFI.go index 346bb3b4..ea08e0b2 100644 --- a/fiReceiverFI.go +++ b/fiReceiverFI.go @@ -106,20 +106,27 @@ func (firfi *FIReceiverFI) UnmarshalJSON(data []byte) error { return nil } -// String writes FIReceiverFI -func (firfi *FIReceiverFI) String(options ...bool) string { +// String returns a fixed-width FIReceiverFI record +func (firfi *FIReceiverFI) String() string { + return firfi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a FIReceiverFI record formatted according to the FormatOptions +func (firfi *FIReceiverFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(201) buf.WriteString(firfi.tag) - buf.WriteString(firfi.LineOneField(options...)) - buf.WriteString(firfi.LineTwoField(options...)) - buf.WriteString(firfi.LineThreeField(options...)) - buf.WriteString(firfi.LineFourField(options...)) - buf.WriteString(firfi.LineFiveField(options...)) - buf.WriteString(firfi.LineSixField(options...)) - - if firfi.parseFirstOption(options) { + buf.WriteString(firfi.FormatLineOne(options)) + buf.WriteString(firfi.FormatLineTwo(options)) + buf.WriteString(firfi.FormatLineThree(options)) + buf.WriteString(firfi.FormatLineFour(options)) + buf.WriteString(firfi.FormatLineFive(options)) + buf.WriteString(firfi.FormatLineSix(options)) + + if options.VariableLengthFields { return firfi.stripDelimiters(buf.String()) } else { return buf.String() @@ -154,31 +161,61 @@ func (firfi *FIReceiverFI) Validate() error { } // LineOneField gets a string of the LineOne field -func (firfi *FIReceiverFI) LineOneField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineOne, 30, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineOneField() string { + return firfi.alphaField(firfi.FIToFI.LineOne, 30) } // LineTwoField gets a string of the LineTwo field -func (firfi *FIReceiverFI) LineTwoField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineTwo, 33, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineTwoField() string { + return firfi.alphaField(firfi.FIToFI.LineTwo, 33) } // LineThreeField gets a string of the LineThree field -func (firfi *FIReceiverFI) LineThreeField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineThree, 33, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineThreeField() string { + return firfi.alphaField(firfi.FIToFI.LineThree, 33) } // LineFourField gets a string of the LineFour field -func (firfi *FIReceiverFI) LineFourField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineFour, 33, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineFourField() string { + return firfi.alphaField(firfi.FIToFI.LineFour, 33) } // LineFiveField gets a string of the LineFive field -func (firfi *FIReceiverFI) LineFiveField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineFive, 33, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineFiveField() string { + return firfi.alphaField(firfi.FIToFI.LineFive, 33) } // LineSixField gets a string of the LineSix field -func (firfi *FIReceiverFI) LineSixField(options ...bool) string { - return firfi.alphaVariableField(firfi.FIToFI.LineSix, 33, firfi.parseFirstOption(options)) +func (firfi *FIReceiverFI) LineSixField() string { + return firfi.alphaField(firfi.FIToFI.LineSix, 33) +} + +// FormatLineOne returns FIToFI.LineOne formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineOne(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineOne, 30, options) +} + +// FormatLineTwo returns FIToFI.LineTwo formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineTwo(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineTwo, 33, options) +} + +// FormatLineThree returns FIToFI.LineThree formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineThree(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineThree, 33, options) +} + +// FormatLineFour returns FIToFI.LineFour formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineFour(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineFour, 33, options) +} + +// FormatLineFive returns FIToFI.LineFive formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineFive(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineFive, 33, options) +} + +// FormatLineSix returns FIToFI.LineSix formatted according to the FormatOptions +func (firfi *FIReceiverFI) FormatLineSix(options FormatOptions) string { + return firfi.formatAlphaField(firfi.FIToFI.LineSix, 33, options) } diff --git a/fiReceiverFI_test.go b/fiReceiverFI_test.go index 2dba54d2..25e667bd 100644 --- a/fiReceiverFI_test.go +++ b/fiReceiverFI_test.go @@ -154,7 +154,7 @@ func TestStringFIReceiverFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringFIReceiverFIOptions validates string() with options +// TestStringFIReceiverFIOptions validates Format() formatted according to the FormatOptions func TestStringFIReceiverFIOptions(t *testing.T) { var line = "{6100}*" r := NewReader(strings.NewReader(line)) @@ -163,9 +163,9 @@ func TestStringFIReceiverFIOptions(t *testing.T) { err := r.parseFIReceiverFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.FIReceiverFI.String() - require.Equal(t, str, "{6100} ") + record := r.currentFEDWireMessage.FIReceiverFI + require.Equal(t, record.String(), "{6100} ") - str = r.currentFEDWireMessage.FIReceiverFI.String(true) - require.Equal(t, str, "{6100}*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6100}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/format_options.go b/format_options.go new file mode 100644 index 00000000..2034880f --- /dev/null +++ b/format_options.go @@ -0,0 +1,7 @@ +package wire + +// FormatOptions specify options for writing wire records to strings +type FormatOptions struct { + VariableLengthFields bool // set to true to use variable length fields instead of fixed-width + NewlineCharacter string // determines line endings - "\n" by default +} diff --git a/grossAmountRemittanceDocument.go b/grossAmountRemittanceDocument.go index 81445174..b3df37a2 100644 --- a/grossAmountRemittanceDocument.go +++ b/grossAmountRemittanceDocument.go @@ -78,16 +78,23 @@ func (gard *GrossAmountRemittanceDocument) UnmarshalJSON(data []byte) error { return nil } -// String writes GrossAmountRemittanceDocument -func (gard *GrossAmountRemittanceDocument) String(options ...bool) string { +// String returns a fixed-width GrossAmountRemittanceDocument record +func (gard *GrossAmountRemittanceDocument) String() string { + return gard.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a GrossAmountRemittanceDocument record formatted according to the FormatOptions +func (gard *GrossAmountRemittanceDocument) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(28) buf.WriteString(gard.tag) - buf.WriteString(gard.CurrencyCodeField(options...)) - buf.WriteString(gard.AmountField(options...)) + buf.WriteString(gard.FormatCurrencyCode(options)) + buf.WriteString(gard.FormatAmount(options)) - if gard.parseFirstOption(options) { + if options.VariableLengthFields { return gard.stripDelimiters(buf.String()) } else { return buf.String() @@ -125,11 +132,21 @@ func (gard *GrossAmountRemittanceDocument) fieldInclusion() error { } // CurrencyCodeField gets a string of the CurrencyCode field -func (gard *GrossAmountRemittanceDocument) CurrencyCodeField(options ...bool) string { - return gard.alphaVariableField(gard.RemittanceAmount.CurrencyCode, 3, gard.parseFirstOption(options)) +func (gard *GrossAmountRemittanceDocument) CurrencyCodeField() string { + return gard.alphaField(gard.RemittanceAmount.CurrencyCode, 3) } // AmountField gets a string of the Amount field -func (gard *GrossAmountRemittanceDocument) AmountField(options ...bool) string { - return gard.alphaVariableField(gard.RemittanceAmount.Amount, 19, gard.parseFirstOption(options)) +func (gard *GrossAmountRemittanceDocument) AmountField() string { + return gard.alphaField(gard.RemittanceAmount.Amount, 19) +} + +// FormatCurrencyCode returns RemittanceAmount.CurrencyCode formatted according to the FormatOptions +func (gard *GrossAmountRemittanceDocument) FormatCurrencyCode(options FormatOptions) string { + return gard.formatAlphaField(gard.RemittanceAmount.CurrencyCode, 3, options) +} + +// FormatAmount returns RemittanceAmount.Amount formatted according to the FormatOptions +func (gard *GrossAmountRemittanceDocument) FormatAmount(options FormatOptions) string { + return gard.formatAlphaField(gard.RemittanceAmount.Amount, 19, options) } diff --git a/grossAmountRemittanceDocument_test.go b/grossAmountRemittanceDocument_test.go index 6920682e..4f72a6ee 100644 --- a/grossAmountRemittanceDocument_test.go +++ b/grossAmountRemittanceDocument_test.go @@ -121,7 +121,7 @@ func TestStringGrossAmountRemittanceDocumentVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringGrossAmountRemittanceDocumentOptions validates string() with options +// TestStringGrossAmountRemittanceDocumentOptions validates Format() formatted according to the FormatOptions func TestStringGrossAmountRemittanceDocumentOptions(t *testing.T) { var line = "{8500}USD1234.56*" r := NewReader(strings.NewReader(line)) @@ -130,9 +130,8 @@ func TestStringGrossAmountRemittanceDocumentOptions(t *testing.T) { err := r.parseGrossAmountRemittanceDocument() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.GrossAmountRemittanceDocument.String() - require.Equal(t, str, "{8500}USD1234.56 ") - - str = r.currentFEDWireMessage.GrossAmountRemittanceDocument.String(true) - require.Equal(t, str, "{8500}USD1234.56*") + record := r.currentFEDWireMessage.GrossAmountRemittanceDocument + require.Equal(t, record.String(), "{8500}USD1234.56 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8500}USD1234.56*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/institutionAccount.go b/institutionAccount.go index abac2d05..8416f596 100644 --- a/institutionAccount.go +++ b/institutionAccount.go @@ -106,20 +106,27 @@ func (iAccount *InstitutionAccount) UnmarshalJSON(data []byte) error { return nil } -// String writes InstitutionAccount -func (iAccount *InstitutionAccount) String(options ...bool) string { +// String returns a fixed-width InstitutionAccount record +func (iAccount *InstitutionAccount) String() string { + return iAccount.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a InstitutionAccount record formatted according to the FormatOptions +func (iAccount *InstitutionAccount) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(186) buf.WriteString(iAccount.tag) - buf.WriteString(iAccount.SwiftFieldTagField(options...)) - buf.WriteString(iAccount.SwiftLineOneField(options...)) - buf.WriteString(iAccount.SwiftLineTwoField(options...)) - buf.WriteString(iAccount.SwiftLineThreeField(options...)) - buf.WriteString(iAccount.SwiftLineFourField(options...)) - buf.WriteString(iAccount.SwiftLineFiveField(options...)) - - if iAccount.parseFirstOption(options) { + buf.WriteString(iAccount.FormatSwiftFieldTag(options)) + buf.WriteString(iAccount.FormatSwiftLineOne(options)) + buf.WriteString(iAccount.FormatSwiftLineTwo(options)) + buf.WriteString(iAccount.FormatSwiftLineThree(options)) + buf.WriteString(iAccount.FormatSwiftLineFour(options)) + buf.WriteString(iAccount.FormatSwiftLineFive(options)) + + if options.VariableLengthFields { return iAccount.stripDelimiters(buf.String()) } else { return buf.String() @@ -166,31 +173,61 @@ func (iAccount *InstitutionAccount) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (iAccount *InstitutionAccount) SwiftFieldTagField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftFieldTag, 5, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftFieldTagField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (iAccount *InstitutionAccount) SwiftLineOneField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftLineOne, 35, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftLineOneField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (iAccount *InstitutionAccount) SwiftLineTwoField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftLineTwo, 35, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftLineTwoField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (iAccount *InstitutionAccount) SwiftLineThreeField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftLineThree, 35, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftLineThreeField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (iAccount *InstitutionAccount) SwiftLineFourField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftLineFour, 35, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftLineFourField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (iAccount *InstitutionAccount) SwiftLineFiveField(options ...bool) string { - return iAccount.alphaVariableField(iAccount.CoverPayment.SwiftLineFive, 35, iAccount.parseFirstOption(options)) +func (iAccount *InstitutionAccount) SwiftLineFiveField() string { + return iAccount.alphaField(iAccount.CoverPayment.SwiftLineFive, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftFieldTag(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftLineOne(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftLineTwo(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftLineThree(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftLineFour(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (iAccount *InstitutionAccount) FormatSwiftLineFive(options FormatOptions) string { + return iAccount.formatAlphaField(iAccount.CoverPayment.SwiftLineFive, 35, options) } diff --git a/institutionAccount_test.go b/institutionAccount_test.go index e92ca568..9cff2dbd 100644 --- a/institutionAccount_test.go +++ b/institutionAccount_test.go @@ -161,7 +161,7 @@ func TestStringInstitutionAccountVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringInstitutionAccountOptions validates string() with options +// TestStringInstitutionAccountOptions validates Format() formatted according to the FormatOptions func TestStringInstitutionAccountOptions(t *testing.T) { var line = "{7057}Swift*" r := NewReader(strings.NewReader(line)) @@ -170,9 +170,8 @@ func TestStringInstitutionAccountOptions(t *testing.T) { err := r.parseInstitutionAccount() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.InstitutionAccount.String() - require.Equal(t, str, "{7057}Swift ") - - str = r.currentFEDWireMessage.InstitutionAccount.String(true) - require.Equal(t, str, "{7057}Swift*") + record := r.currentFEDWireMessage.InstitutionAccount + require.Equal(t, record.String(), "{7057}Swift ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7057}Swift*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/instructedAmount.go b/instructedAmount.go index a9d4ebd5..d74ee079 100644 --- a/instructedAmount.go +++ b/instructedAmount.go @@ -81,14 +81,21 @@ func (ia *InstructedAmount) UnmarshalJSON(data []byte) error { return nil } -// String writes InstructedAmount -func (ia *InstructedAmount) String(options ...bool) string { +// String returns a fixed-width InstructedAmount record +func (ia *InstructedAmount) String() string { + return ia.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a InstructedAmount record formatted according to the FormatOptions +func (ia *InstructedAmount) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(24) buf.WriteString(ia.tag) - buf.WriteString(ia.CurrencyCodeField(options...)) - buf.WriteString(ia.AmountField(options...)) + buf.WriteString(ia.FormatCurrencyCode(options)) + buf.WriteString(ia.FormatAmount(options)) return buf.String() } @@ -125,11 +132,21 @@ func (ia *InstructedAmount) fieldInclusion() error { } // CurrencyCodeField gets a string of the CurrencyCode field -func (ia *InstructedAmount) CurrencyCodeField(options ...bool) string { - return ia.alphaVariableField(ia.CurrencyCode, 3, ia.parseFirstOption(options)) +func (ia *InstructedAmount) CurrencyCodeField() string { + return ia.alphaField(ia.CurrencyCode, 3) } // AmountField gets a string of the Amount field -func (ia *InstructedAmount) AmountField(options ...bool) string { - return ia.alphaVariableField(ia.Amount, 15, ia.parseFirstOption(options)) +func (ia *InstructedAmount) AmountField() string { + return ia.alphaField(ia.Amount, 15) +} + +// FormatCurrencyCode returns CurrencyCode formatted according to the FormatOptions +func (ia *InstructedAmount) FormatCurrencyCode(options FormatOptions) string { + return ia.formatAlphaField(ia.CurrencyCode, 3, options) +} + +// FormatAmount returns Amount formatted according to the FormatOptions +func (ia *InstructedAmount) FormatAmount(options FormatOptions) string { + return ia.formatAlphaField(ia.Amount, 15, options) } diff --git a/instructedAmount_test.go b/instructedAmount_test.go index 99c44ffd..bc65e9ca 100644 --- a/instructedAmount_test.go +++ b/instructedAmount_test.go @@ -127,7 +127,7 @@ func TestStringInstructedAmountVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringInstructedAmountOptions validates string() with options +// TestStringInstructedAmountOptions validates Format() formatted according to the FormatOptions func TestStringInstructedAmountOptions(t *testing.T) { var line = "{3710}USD4567,89*" r := NewReader(strings.NewReader(line)) @@ -136,9 +136,8 @@ func TestStringInstructedAmountOptions(t *testing.T) { err := r.parseInstructedAmount() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.InstructedAmount.String() - require.Equal(t, str, "{3710}USD4567,89 ") - - str = r.currentFEDWireMessage.InstructedAmount.String(true) - require.Equal(t, str, "{3710}USD4567,89*") + record := r.currentFEDWireMessage.InstructedAmount + require.Equal(t, record.String(), "{3710}USD4567,89 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3710}USD4567,89*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/instructingFI.go b/instructingFI.go index f085a664..dd3a54b4 100644 --- a/instructingFI.go +++ b/instructingFI.go @@ -100,20 +100,27 @@ func (ifi *InstructingFI) UnmarshalJSON(data []byte) error { return nil } -// String writes InstructingFI -func (ifi *InstructingFI) String(options ...bool) string { +// String returns a fixed-width InstructingFI record +func (ifi *InstructingFI) String() string { + return ifi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a InstructingFI record formatted according to the FormatOptions +func (ifi *InstructingFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(ifi.tag) buf.WriteString(ifi.IdentificationCodeField()) - buf.WriteString(ifi.IdentifierField(options...)) - buf.WriteString(ifi.NameField(options...)) - buf.WriteString(ifi.AddressLineOneField(options...)) - buf.WriteString(ifi.AddressLineTwoField(options...)) - buf.WriteString(ifi.AddressLineThreeField(options...)) + buf.WriteString(ifi.FormatIdentifier(options)) + buf.WriteString(ifi.FormatName(options)) + buf.WriteString(ifi.FormatAddressLineOne(options)) + buf.WriteString(ifi.FormatAddressLineTwo(options)) + buf.WriteString(ifi.FormatAddressLineThree(options)) - if ifi.parseFirstOption(options) { + if options.VariableLengthFields { return ifi.stripDelimiters(buf.String()) } else { return buf.String() @@ -176,26 +183,51 @@ func (ifi *InstructingFI) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (ifi *InstructingFI) IdentifierField(options ...bool) string { - return ifi.alphaVariableField(ifi.FinancialInstitution.Identifier, 34, ifi.parseFirstOption(options)) +func (ifi *InstructingFI) IdentifierField() string { + return ifi.alphaField(ifi.FinancialInstitution.Identifier, 34) } // NameField gets a string of the Name field -func (ifi *InstructingFI) NameField(options ...bool) string { - return ifi.alphaVariableField(ifi.FinancialInstitution.Name, 35, ifi.parseFirstOption(options)) +func (ifi *InstructingFI) NameField() string { + return ifi.alphaField(ifi.FinancialInstitution.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (ifi *InstructingFI) AddressLineOneField(options ...bool) string { - return ifi.alphaVariableField(ifi.FinancialInstitution.Address.AddressLineOne, 35, ifi.parseFirstOption(options)) +func (ifi *InstructingFI) AddressLineOneField() string { + return ifi.alphaField(ifi.FinancialInstitution.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (ifi *InstructingFI) AddressLineTwoField(options ...bool) string { - return ifi.alphaVariableField(ifi.FinancialInstitution.Address.AddressLineTwo, 35, ifi.parseFirstOption(options)) +func (ifi *InstructingFI) AddressLineTwoField() string { + return ifi.alphaField(ifi.FinancialInstitution.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (ifi *InstructingFI) AddressLineThreeField(options ...bool) string { - return ifi.alphaVariableField(ifi.FinancialInstitution.Address.AddressLineThree, 35, ifi.parseFirstOption(options)) +func (ifi *InstructingFI) AddressLineThreeField() string { + return ifi.alphaField(ifi.FinancialInstitution.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns Advice.LineOne formatted according to the FormatOptions +func (ifi *InstructingFI) FormatIdentifier(options FormatOptions) string { + return ifi.formatAlphaField(ifi.FinancialInstitution.Identifier, 34, options) +} + +// FormatName returns Advice.LineOne formatted according to the FormatOptions +func (ifi *InstructingFI) FormatName(options FormatOptions) string { + return ifi.formatAlphaField(ifi.FinancialInstitution.Name, 35, options) +} + +// FormatAddressLineOne returns Advice.LineOne formatted according to the FormatOptions +func (ifi *InstructingFI) FormatAddressLineOne(options FormatOptions) string { + return ifi.formatAlphaField(ifi.FinancialInstitution.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns Advice.LineOne formatted according to the FormatOptions +func (ifi *InstructingFI) FormatAddressLineTwo(options FormatOptions) string { + return ifi.formatAlphaField(ifi.FinancialInstitution.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns Advice.LineOne formatted according to the FormatOptions +func (ifi *InstructingFI) FormatAddressLineThree(options FormatOptions) string { + return ifi.formatAlphaField(ifi.FinancialInstitution.Address.AddressLineThree, 35, options) } diff --git a/instructingFI_test.go b/instructingFI_test.go index 444abb16..6a9fe9cc 100644 --- a/instructingFI_test.go +++ b/instructingFI_test.go @@ -181,7 +181,7 @@ func TestStringInstructingFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringInstructingFIOptions validates string() with options +// TestStringInstructingFIOptions validates Format() formatted according to the FormatOptions func TestStringInstructingFIOptions(t *testing.T) { var line = "{5200}D12*" r := NewReader(strings.NewReader(line)) @@ -190,9 +190,8 @@ func TestStringInstructingFIOptions(t *testing.T) { err := r.parseInstructingFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.InstructingFI.String() - require.Equal(t, str, "{5200}D12 ") - - str = r.currentFEDWireMessage.InstructingFI.String(true) - require.Equal(t, str, "{5200}D12*") + record := r.currentFEDWireMessage.InstructingFI + require.Equal(t, record.String(), "{5200}D12 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5200}D12*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/intermediaryInstitution.go b/intermediaryInstitution.go index 11f233da..bddaf80c 100644 --- a/intermediaryInstitution.go +++ b/intermediaryInstitution.go @@ -106,20 +106,27 @@ func (ii *IntermediaryInstitution) UnmarshalJSON(data []byte) error { return nil } -// String writes IntermediaryInstitution -func (ii *IntermediaryInstitution) String(options ...bool) string { +// String returns a fixed-width IntermediaryInstitution record +func (ii *IntermediaryInstitution) String() string { + return ii.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a IntermediaryInstitution record formatted according to the FormatOptions +func (ii *IntermediaryInstitution) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(186) buf.WriteString(ii.tag) - buf.WriteString(ii.SwiftFieldTagField(options...)) - buf.WriteString(ii.SwiftLineOneField(options...)) - buf.WriteString(ii.SwiftLineTwoField(options...)) - buf.WriteString(ii.SwiftLineThreeField(options...)) - buf.WriteString(ii.SwiftLineFourField(options...)) - buf.WriteString(ii.SwiftLineFiveField(options...)) - - if ii.parseFirstOption(options) { + buf.WriteString(ii.FormatSwiftFieldTag(options)) + buf.WriteString(ii.FormatSwiftLineOne(options)) + buf.WriteString(ii.FormatSwiftLineTwo(options)) + buf.WriteString(ii.FormatSwiftLineThree(options)) + buf.WriteString(ii.FormatSwiftLineFour(options)) + buf.WriteString(ii.FormatSwiftLineFive(options)) + + if options.VariableLengthFields { return ii.stripDelimiters(buf.String()) } else { return buf.String() @@ -166,31 +173,61 @@ func (ii *IntermediaryInstitution) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (ii *IntermediaryInstitution) SwiftFieldTagField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftFieldTag, 5, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftFieldTagField() string { + return ii.alphaField(ii.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (ii *IntermediaryInstitution) SwiftLineOneField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftLineOne, 35, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftLineOneField() string { + return ii.alphaField(ii.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (ii *IntermediaryInstitution) SwiftLineTwoField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftLineTwo, 35, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftLineTwoField() string { + return ii.alphaField(ii.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (ii *IntermediaryInstitution) SwiftLineThreeField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftLineThree, 35, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftLineThreeField() string { + return ii.alphaField(ii.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (ii *IntermediaryInstitution) SwiftLineFourField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftLineFour, 35, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftLineFourField() string { + return ii.alphaField(ii.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (ii *IntermediaryInstitution) SwiftLineFiveField(options ...bool) string { - return ii.alphaVariableField(ii.CoverPayment.SwiftLineFive, 35, ii.parseFirstOption(options)) +func (ii *IntermediaryInstitution) SwiftLineFiveField() string { + return ii.alphaField(ii.CoverPayment.SwiftLineFive, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftFieldTag(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftLineOne(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftLineTwo(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftLineThree(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftLineFour(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (ii *IntermediaryInstitution) FormatSwiftLineFive(options FormatOptions) string { + return ii.formatAlphaField(ii.CoverPayment.SwiftLineFive, 35, options) } diff --git a/intermediaryInstitution_test.go b/intermediaryInstitution_test.go index ef1aefb0..ab7f0b06 100644 --- a/intermediaryInstitution_test.go +++ b/intermediaryInstitution_test.go @@ -161,7 +161,7 @@ func TestStringIntermediaryInstitutionVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringIntermediaryInstitutionOptions validates string() with options +// TestStringIntermediaryInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringIntermediaryInstitutionOptions(t *testing.T) { var line = "{7056}*" r := NewReader(strings.NewReader(line)) @@ -170,9 +170,8 @@ func TestStringIntermediaryInstitutionOptions(t *testing.T) { err := r.parseIntermediaryInstitution() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.IntermediaryInstitution.String() - require.Equal(t, str, "{7056} ") - - str = r.currentFEDWireMessage.IntermediaryInstitution.String(true) - require.Equal(t, str, "{7056}*") + record := r.currentFEDWireMessage.IntermediaryInstitution + require.Equal(t, record.String(), "{7056} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7056}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/localInstrument.go b/localInstrument.go index 1dbdcc58..183719dc 100644 --- a/localInstrument.go +++ b/localInstrument.go @@ -80,16 +80,23 @@ func (li *LocalInstrument) UnmarshalJSON(data []byte) error { return nil } -// String writes LocalInstrument -func (li *LocalInstrument) String(options ...bool) string { +// String returns a fixed-width LocalInstrument record +func (li *LocalInstrument) String() string { + return li.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a LocalInstrument record formatted according to the FormatOptions +func (li *LocalInstrument) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(45) buf.WriteString(li.tag) - buf.WriteString(li.LocalInstrumentCodeField(options...)) - buf.WriteString(li.ProprietaryCodeField(options...)) + buf.WriteString(li.FormatLocalInstrumentCode(options)) + buf.WriteString(li.FormatProprietaryCode(options)) - if li.parseFirstOption(options) { + if options.VariableLengthFields { return li.stripDelimiters(buf.String()) } else { return buf.String() @@ -125,11 +132,21 @@ func (li *LocalInstrument) fieldInclusion() error { } // LocalInstrumentCodeField gets a string of LocalInstrumentCode field -func (li *LocalInstrument) LocalInstrumentCodeField(options ...bool) string { - return li.alphaVariableField(li.LocalInstrumentCode, 4, li.parseFirstOption(options)) +func (li *LocalInstrument) LocalInstrumentCodeField() string { + return li.alphaField(li.LocalInstrumentCode, 4) } // ProprietaryCodeField gets a string of ProprietaryCode field -func (li *LocalInstrument) ProprietaryCodeField(options ...bool) string { - return li.alphaVariableField(li.ProprietaryCode, 35, li.parseFirstOption(options)) +func (li *LocalInstrument) ProprietaryCodeField() string { + return li.alphaField(li.ProprietaryCode, 35) +} + +// FormatLocalInstrumentCode returns LocalInstrumentCode formatted according to the FormatOptions +func (li *LocalInstrument) FormatLocalInstrumentCode(options FormatOptions) string { + return li.formatAlphaField(li.LocalInstrumentCode, 4, options) +} + +// FormatProprietaryCode returns ProprietaryCode formatted according to the FormatOptions +func (li *LocalInstrument) FormatProprietaryCode(options FormatOptions) string { + return li.formatAlphaField(li.ProprietaryCode, 35, options) } diff --git a/localInstrument_test.go b/localInstrument_test.go index b832cd21..a9cb94f4 100644 --- a/localInstrument_test.go +++ b/localInstrument_test.go @@ -118,7 +118,7 @@ func TestStringLocalInstrumentVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringLocalInstrumentOptions validates string() with options +// TestStringLocalInstrumentOptions validates Format() formatted according to the FormatOptions func TestStringLocalInstrumentOptions(t *testing.T) { var line = "{3610}ANSI*" r := NewReader(strings.NewReader(line)) @@ -127,9 +127,8 @@ func TestStringLocalInstrumentOptions(t *testing.T) { err := r.parseLocalInstrument() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.LocalInstrument.String() - require.Equal(t, str, "{3610}ANSI ") - - str = r.currentFEDWireMessage.LocalInstrument.String(true) - require.Equal(t, str, "{3610}ANSI*") + record := r.currentFEDWireMessage.LocalInstrument + require.Equal(t, record.String(), "{3610}ANSI ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3610}ANSI*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/messageDisposition.go b/messageDisposition.go index 1a63f3dc..c7869107 100644 --- a/messageDisposition.go +++ b/messageDisposition.go @@ -101,18 +101,25 @@ func (md *MessageDisposition) UnmarshalJSON(data []byte) error { return nil } -// String writes MessageDisposition -func (md *MessageDisposition) String(options ...bool) string { +// String returns a fixed-width MessageDisposition record +func (md *MessageDisposition) String() string { + return md.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a MessageDisposition record formatted according to the FormatOptions +func (md *MessageDisposition) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(11) buf.WriteString(md.tag) - buf.WriteString(md.MessageDispositionFormatVersionField(options...)) - buf.WriteString(md.MessageDispositionTestProductionCodeField(options...)) - buf.WriteString(md.MessageDispositionMessageDuplicationCodeField(options...)) - buf.WriteString(md.MessageDispositionMessageStatusIndicatorField(options...)) + buf.WriteString(md.FormatMessageDispositionFormatVersion(options)) + buf.WriteString(md.FormatMessageDispositionTestProductionCode(options)) + buf.WriteString(md.FormatMessageDispositionMessageDuplicationCode(options)) + buf.WriteString(md.FormatMessageDispositionMessageStatusIndicator(options)) - if md.parseFirstOption(options) { + if options.VariableLengthFields { return md.stripDelimiters(buf.String()) } else { return buf.String() @@ -130,21 +137,41 @@ func (md *MessageDisposition) Validate() error { } // MessageDispositionFormatVersionField gets a string of the FormatVersion field -func (md *MessageDisposition) MessageDispositionFormatVersionField(options ...bool) string { - return md.alphaVariableField(md.FormatVersion, 2, md.parseFirstOption(options)) +func (md *MessageDisposition) MessageDispositionFormatVersionField() string { + return md.alphaField(md.FormatVersion, 2) } // MessageDispositionTestProductionCodeField gets a string of the TestProductionCoden field -func (md *MessageDisposition) MessageDispositionTestProductionCodeField(options ...bool) string { - return md.alphaVariableField(md.TestProductionCode, 1, md.parseFirstOption(options)) +func (md *MessageDisposition) MessageDispositionTestProductionCodeField() string { + return md.alphaField(md.TestProductionCode, 1) } // MessageDispositionMessageDuplicationCodeField gets a string of the MessageDuplicationCode field -func (md *MessageDisposition) MessageDispositionMessageDuplicationCodeField(options ...bool) string { - return md.alphaVariableField(md.MessageDuplicationCode, 1, md.parseFirstOption(options)) +func (md *MessageDisposition) MessageDispositionMessageDuplicationCodeField() string { + return md.alphaField(md.MessageDuplicationCode, 1) } // MessageDispositionMessageStatusIndicatorField gets a string of the MessageDuplicationCode field -func (md *MessageDisposition) MessageDispositionMessageStatusIndicatorField(options ...bool) string { - return md.alphaVariableField(md.MessageStatusIndicator, 1, md.parseFirstOption(options)) +func (md *MessageDisposition) MessageDispositionMessageStatusIndicatorField() string { + return md.alphaField(md.MessageStatusIndicator, 1) +} + +// FormatMessageDispositionFormatVersion returns FormatVersion formatted according to the FormatOptions +func (md *MessageDisposition) FormatMessageDispositionFormatVersion(options FormatOptions) string { + return md.formatAlphaField(md.FormatVersion, 2, options) +} + +// FormatMessageDispositionTestProductionCode returns TestProductionCode formatted according to the FormatOptions +func (md *MessageDisposition) FormatMessageDispositionTestProductionCode(options FormatOptions) string { + return md.formatAlphaField(md.TestProductionCode, 1, options) +} + +// FormatMessageDispositionMessageDuplicationCode returns MessageDuplicationCode formatted according to the FormatOptions +func (md *MessageDisposition) FormatMessageDispositionMessageDuplicationCode(options FormatOptions) string { + return md.formatAlphaField(md.MessageDuplicationCode, 1, options) +} + +// FormatMessageDispositionMessageStatusIndicator returns MessageStatusIndicator formatted according to the FormatOptions +func (md *MessageDisposition) FormatMessageDispositionMessageStatusIndicator(options FormatOptions) string { + return md.formatAlphaField(md.MessageStatusIndicator, 1, options) } diff --git a/messageDisposition_test.go b/messageDisposition_test.go index 2d7ce7d3..174f7414 100644 --- a/messageDisposition_test.go +++ b/messageDisposition_test.go @@ -90,7 +90,7 @@ func TestStringMessageDispositionVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringMessageDispositionOptions validates string() with options +// TestStringMessageDispositionOptions validates Format() formatted according to the FormatOptions func TestStringMessageDispositionOptions(t *testing.T) { var line = "{1100}" r := NewReader(strings.NewReader(line)) @@ -99,9 +99,8 @@ func TestStringMessageDispositionOptions(t *testing.T) { err := r.parseMessageDisposition() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.MessageDisposition.String() - require.Equal(t, str, "{1100} ") - - str = r.currentFEDWireMessage.MessageDisposition.String(true) - require.Equal(t, str, "{1100}*") + record := r.currentFEDWireMessage.MessageDisposition + require.Equal(t, record.String(), "{1100} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1100}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/orderingCustomer.go b/orderingCustomer.go index fffe91e9..037ac1de 100644 --- a/orderingCustomer.go +++ b/orderingCustomer.go @@ -106,20 +106,27 @@ func (oc *OrderingCustomer) UnmarshalJSON(data []byte) error { return nil } -// String writes OrderingCustomer -func (oc *OrderingCustomer) String(options ...bool) string { +// String returns a fixed-width OrderingCustomer record +func (oc *OrderingCustomer) String() string { + return oc.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OrderingCustomer record formatted according to the FormatOptions +func (oc *OrderingCustomer) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(186) buf.WriteString(oc.tag) - buf.WriteString(oc.SwiftFieldTagField(options...)) - buf.WriteString(oc.SwiftLineOneField(options...)) - buf.WriteString(oc.SwiftLineTwoField(options...)) - buf.WriteString(oc.SwiftLineThreeField(options...)) - buf.WriteString(oc.SwiftLineFourField(options...)) - buf.WriteString(oc.SwiftLineFiveField(options...)) + buf.WriteString(oc.FormatSwiftFieldTag(options)) + buf.WriteString(oc.FormatSwiftLineOne(options)) + buf.WriteString(oc.FormatSwiftLineTwo(options)) + buf.WriteString(oc.FormatSwiftLineThree(options)) + buf.WriteString(oc.FormatSwiftLineFour(options)) + buf.WriteString(oc.FormatSwiftLineFive(options)) - if oc.parseFirstOption(options) { + if options.VariableLengthFields { return oc.stripDelimiters(buf.String()) } else { return buf.String() @@ -166,31 +173,61 @@ func (oc *OrderingCustomer) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (oc *OrderingCustomer) SwiftFieldTagField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftFieldTag, 5, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftFieldTagField() string { + return oc.alphaField(oc.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (oc *OrderingCustomer) SwiftLineOneField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftLineOne, 35, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftLineOneField() string { + return oc.alphaField(oc.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (oc *OrderingCustomer) SwiftLineTwoField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftLineTwo, 35, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftLineTwoField() string { + return oc.alphaField(oc.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (oc *OrderingCustomer) SwiftLineThreeField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftLineThree, 35, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftLineThreeField() string { + return oc.alphaField(oc.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (oc *OrderingCustomer) SwiftLineFourField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftLineFour, 35, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftLineFourField() string { + return oc.alphaField(oc.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (oc *OrderingCustomer) SwiftLineFiveField(options ...bool) string { - return oc.alphaVariableField(oc.CoverPayment.SwiftLineFive, 35, oc.parseFirstOption(options)) +func (oc *OrderingCustomer) SwiftLineFiveField() string { + return oc.alphaField(oc.CoverPayment.SwiftLineFive, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftFieldTag(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftLineOne(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftLineTwo(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftLineThree(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftLineFour(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (oc *OrderingCustomer) FormatSwiftLineFive(options FormatOptions) string { + return oc.formatAlphaField(oc.CoverPayment.SwiftLineFive, 35, options) } diff --git a/orderingCustomer_test.go b/orderingCustomer_test.go index 18b39919..0fd92aa3 100644 --- a/orderingCustomer_test.go +++ b/orderingCustomer_test.go @@ -161,7 +161,7 @@ func TestStringOrderingCustomerVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOrderingCustomerOptions validates string() with options +// TestStringOrderingCustomerOptions validates Format() formatted according to the FormatOptions func TestStringOrderingCustomerOptions(t *testing.T) { var line = "{7050}" r := NewReader(strings.NewReader(line)) @@ -170,9 +170,8 @@ func TestStringOrderingCustomerOptions(t *testing.T) { err := r.parseOrderingCustomer() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OrderingCustomer.String() - require.Equal(t, str, "{7050} ") - - str = r.currentFEDWireMessage.OrderingCustomer.String(true) - require.Equal(t, str, "{7050}*") + record := r.currentFEDWireMessage.OrderingCustomer + require.Equal(t, record.String(), "{7050} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7050}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/orderingInstitution.go b/orderingInstitution.go index b26a89cd..c6d59431 100644 --- a/orderingInstitution.go +++ b/orderingInstitution.go @@ -106,20 +106,27 @@ func (oi *OrderingInstitution) UnmarshalJSON(data []byte) error { return nil } -// String writes OrderingInstitution -func (oi *OrderingInstitution) String(options ...bool) string { +// String returns a fixed-width OrderingInstitution record +func (oi *OrderingInstitution) String() string { + return oi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OrderingInstitution record formatted according to the FormatOptions +func (oi *OrderingInstitution) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(186) buf.WriteString(oi.tag) - buf.WriteString(oi.SwiftFieldTagField(options...)) - buf.WriteString(oi.SwiftLineOneField(options...)) - buf.WriteString(oi.SwiftLineTwoField(options...)) - buf.WriteString(oi.SwiftLineThreeField(options...)) - buf.WriteString(oi.SwiftLineFourField(options...)) - buf.WriteString(oi.SwiftLineFiveField(options...)) + buf.WriteString(oi.FormatSwiftFieldTag(options)) + buf.WriteString(oi.FormatSwiftLineOne(options)) + buf.WriteString(oi.FormatSwiftLineTwo(options)) + buf.WriteString(oi.FormatSwiftLineThree(options)) + buf.WriteString(oi.FormatSwiftLineFour(options)) + buf.WriteString(oi.FormatSwiftLineFive(options)) - if oi.parseFirstOption(options) { + if options.VariableLengthFields { return oi.stripDelimiters(buf.String()) } else { return buf.String() @@ -166,31 +173,61 @@ func (oi *OrderingInstitution) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (oi *OrderingInstitution) SwiftFieldTagField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftFieldTag, 5, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftFieldTagField() string { + return oi.alphaField(oi.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (oi *OrderingInstitution) SwiftLineOneField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftLineOne, 35, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftLineOneField() string { + return oi.alphaField(oi.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (oi *OrderingInstitution) SwiftLineTwoField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftLineTwo, 35, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftLineTwoField() string { + return oi.alphaField(oi.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (oi *OrderingInstitution) SwiftLineThreeField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftLineThree, 35, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftLineThreeField() string { + return oi.alphaField(oi.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (oi *OrderingInstitution) SwiftLineFourField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftLineFour, 35, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftLineFourField() string { + return oi.alphaField(oi.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (oi *OrderingInstitution) SwiftLineFiveField(options ...bool) string { - return oi.alphaVariableField(oi.CoverPayment.SwiftLineFive, 35, oi.parseFirstOption(options)) +func (oi *OrderingInstitution) SwiftLineFiveField() string { + return oi.alphaField(oi.CoverPayment.SwiftLineFive, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftFieldTag(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftLineOne(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftLineTwo(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftLineThree(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftLineFour(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (oi *OrderingInstitution) FormatSwiftLineFive(options FormatOptions) string { + return oi.formatAlphaField(oi.CoverPayment.SwiftLineFive, 35, options) } diff --git a/orderingInstitution_test.go b/orderingInstitution_test.go index d2e0ea9c..ff7298f8 100644 --- a/orderingInstitution_test.go +++ b/orderingInstitution_test.go @@ -160,7 +160,7 @@ func TestStringOrderingInstitutionVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOrderingInstitutionOptions validates string() with options +// TestStringOrderingInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringOrderingInstitutionOptions(t *testing.T) { var line = "{7052}" r := NewReader(strings.NewReader(line)) @@ -169,9 +169,8 @@ func TestStringOrderingInstitutionOptions(t *testing.T) { err := r.parseOrderingInstitution() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OrderingInstitution.String() - require.Equal(t, str, "{7052} ") - - str = r.currentFEDWireMessage.OrderingInstitution.String(true) - require.Equal(t, str, "{7052}*") + record := r.currentFEDWireMessage.OrderingInstitution + require.Equal(t, record.String(), "{7052} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7052}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originator.go b/originator.go index d080c9ba..53642e79 100644 --- a/originator.go +++ b/originator.go @@ -100,20 +100,27 @@ func (o *Originator) UnmarshalJSON(data []byte) error { return nil } -// String writes Originator -func (o *Originator) String(options ...bool) string { +// String returns a fixed-width Originator record +func (o *Originator) String() string { + return o.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a Originator record formatted according to the FormatOptions +func (o *Originator) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(o.tag) buf.WriteString(o.IdentificationCodeField()) - buf.WriteString(o.IdentifierField(options...)) - buf.WriteString(o.NameField(options...)) - buf.WriteString(o.AddressLineOneField(options...)) - buf.WriteString(o.AddressLineTwoField(options...)) - buf.WriteString(o.AddressLineThreeField(options...)) + buf.WriteString(o.FormatIdentifier(options)) + buf.WriteString(o.FormatName(options)) + buf.WriteString(o.FormatAddressLineOne(options)) + buf.WriteString(o.FormatAddressLineTwo(options)) + buf.WriteString(o.FormatAddressLineThree(options)) - if o.parseFirstOption(options) { + if options.VariableLengthFields { return o.stripDelimiters(buf.String()) } else { return buf.String() @@ -169,26 +176,51 @@ func (o *Originator) IdentificationCodeField() string { } // IdentifierField gets a string of the Identifier field -func (o *Originator) IdentifierField(options ...bool) string { - return o.alphaVariableField(o.Personal.Identifier, 34, o.parseFirstOption(options)) +func (o *Originator) IdentifierField() string { + return o.alphaField(o.Personal.Identifier, 34) } // NameField gets a string of the Name field -func (o *Originator) NameField(options ...bool) string { - return o.alphaVariableField(o.Personal.Name, 35, o.parseFirstOption(options)) +func (o *Originator) NameField() string { + return o.alphaField(o.Personal.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (o *Originator) AddressLineOneField(options ...bool) string { - return o.alphaVariableField(o.Personal.Address.AddressLineOne, 35, o.parseFirstOption(options)) +func (o *Originator) AddressLineOneField() string { + return o.alphaField(o.Personal.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (o *Originator) AddressLineTwoField(options ...bool) string { - return o.alphaVariableField(o.Personal.Address.AddressLineTwo, 35, o.parseFirstOption(options)) +func (o *Originator) AddressLineTwoField() string { + return o.alphaField(o.Personal.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (o *Originator) AddressLineThreeField(options ...bool) string { - return o.alphaVariableField(o.Personal.Address.AddressLineThree, 35, o.parseFirstOption(options)) +func (o *Originator) AddressLineThreeField() string { + return o.alphaField(o.Personal.Address.AddressLineThree, 35) +} + +// FormatIdentifier returns Personal.Identifier formatted according to the FormatOptions +func (o *Originator) FormatIdentifier(options FormatOptions) string { + return o.formatAlphaField(o.Personal.Identifier, 34, options) +} + +// FormatName returns Personal.Name formatted according to the FormatOptions +func (o *Originator) FormatName(options FormatOptions) string { + return o.formatAlphaField(o.Personal.Name, 35, options) +} + +// FormatAddressLineOne returns Address.AddressLineOne formatted according to the FormatOptions +func (o *Originator) FormatAddressLineOne(options FormatOptions) string { + return o.formatAlphaField(o.Personal.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns Address.AddressLineTwo formatted according to the FormatOptions +func (o *Originator) FormatAddressLineTwo(options FormatOptions) string { + return o.formatAlphaField(o.Personal.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns Address.AddressLineThree formatted according to the FormatOptions +func (o *Originator) FormatAddressLineThree(options FormatOptions) string { + return o.formatAlphaField(o.Personal.Address.AddressLineThree, 35, options) } diff --git a/originatorFI.go b/originatorFI.go index 0362e2e4..4bc7757b 100644 --- a/originatorFI.go +++ b/originatorFI.go @@ -106,20 +106,27 @@ func (ofi *OriginatorFI) UnmarshalJSON(data []byte) error { return nil } -// String writes OriginatorFI -func (ofi *OriginatorFI) String(options ...bool) string { +// String returns a fixed-width OriginatorFI record +func (ofi *OriginatorFI) String() string { + return ofi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OriginatorFI record formatted according to the FormatOptions +func (ofi *OriginatorFI) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(ofi.tag) - buf.WriteString(ofi.IdentificationCodeField(options...)) - buf.WriteString(ofi.IdentifierField(options...)) - buf.WriteString(ofi.NameField(options...)) - buf.WriteString(ofi.AddressLineOneField(options...)) - buf.WriteString(ofi.AddressLineTwoField(options...)) - buf.WriteString(ofi.AddressLineThreeField(options...)) + buf.WriteString(ofi.FormatIdentificationCode(options)) + buf.WriteString(ofi.FormatIdentifier(options)) + buf.WriteString(ofi.FormatName(options)) + buf.WriteString(ofi.FormatAddressLineOne(options)) + buf.WriteString(ofi.FormatAddressLineTwo(options)) + buf.WriteString(ofi.FormatAddressLineThree(options)) - if ofi.parseFirstOption(options) { + if options.VariableLengthFields { return ofi.stripDelimiters(buf.String()) } else { return buf.String() @@ -177,31 +184,61 @@ func (ofi *OriginatorFI) fieldInclusion() error { } // IdentificationCodeField gets a string of the IdentificationCode field -func (ofi *OriginatorFI) IdentificationCodeField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.IdentificationCode, 1, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) IdentificationCodeField() string { + return ofi.alphaField(ofi.FinancialInstitution.IdentificationCode, 1) } // IdentifierField gets a string of the Identifier field -func (ofi *OriginatorFI) IdentifierField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.Identifier, 34, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) IdentifierField() string { + return ofi.alphaField(ofi.FinancialInstitution.Identifier, 34) } // NameField gets a string of the Name field -func (ofi *OriginatorFI) NameField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.Name, 35, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) NameField() string { + return ofi.alphaField(ofi.FinancialInstitution.Name, 35) } // AddressLineOneField gets a string of AddressLineOne field -func (ofi *OriginatorFI) AddressLineOneField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.Address.AddressLineOne, 35, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) AddressLineOneField() string { + return ofi.alphaField(ofi.FinancialInstitution.Address.AddressLineOne, 35) } // AddressLineTwoField gets a string of AddressLineTwo field -func (ofi *OriginatorFI) AddressLineTwoField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.Address.AddressLineTwo, 35, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) AddressLineTwoField() string { + return ofi.alphaField(ofi.FinancialInstitution.Address.AddressLineTwo, 35) } // AddressLineThreeField gets a string of AddressLineThree field -func (ofi *OriginatorFI) AddressLineThreeField(options ...bool) string { - return ofi.alphaVariableField(ofi.FinancialInstitution.Address.AddressLineThree, 35, ofi.parseFirstOption(options)) +func (ofi *OriginatorFI) AddressLineThreeField() string { + return ofi.alphaField(ofi.FinancialInstitution.Address.AddressLineThree, 35) +} + +// FormatIdentificationCode returns FinancialInstitution.IdentificationCode formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatIdentificationCode(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.IdentificationCode, 1, options) +} + +// FormatIdentifier returns FinancialInstitution.Identifier formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatIdentifier(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.Identifier, 34, options) +} + +// FormatName returns FinancialInstitution.Name formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatName(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.Name, 35, options) +} + +// FormatAddressLineOne returns Address.AddressLineOne formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatAddressLineOne(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.Address.AddressLineOne, 35, options) +} + +// FormatAddressLineTwo returns Address.AddressLineTwo formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatAddressLineTwo(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.Address.AddressLineTwo, 35, options) +} + +// FormatAddressLineThree returns Address.AddressLineThree formatted according to the FormatOptions +func (ofi *OriginatorFI) FormatAddressLineThree(options FormatOptions) string { + return ofi.formatAlphaField(ofi.FinancialInstitution.Address.AddressLineThree, 35, options) } diff --git a/originatorFI_test.go b/originatorFI_test.go index aca23c2c..baa66fa3 100644 --- a/originatorFI_test.go +++ b/originatorFI_test.go @@ -181,7 +181,7 @@ func TestStringOriginatorFIVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOriginatorFIOptions validates string() with options +// TestStringOriginatorFIOptions validates Format() formatted according to the FormatOptions func TestStringOriginatorFIOptions(t *testing.T) { var line = "{5100}B1*" r := NewReader(strings.NewReader(line)) @@ -190,9 +190,8 @@ func TestStringOriginatorFIOptions(t *testing.T) { err := r.parseOriginatorFI() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OriginatorFI.String() - require.Equal(t, str, "{5100}B1 ") - - str = r.currentFEDWireMessage.OriginatorFI.String(true) - require.Equal(t, str, "{5100}B1*") + record := r.currentFEDWireMessage.OriginatorFI + require.Equal(t, record.String(), "{5100}B1 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5100}B1*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originatorOptionF.go b/originatorOptionF.go index eb4d6e27..9ceea185 100644 --- a/originatorOptionF.go +++ b/originatorOptionF.go @@ -163,19 +163,26 @@ func (oof *OriginatorOptionF) UnmarshalJSON(data []byte) error { return nil } -// String writes OriginatorOptionF -func (oof *OriginatorOptionF) String(options ...bool) string { +// String returns a fixed-width OriginatorOptionF record +func (oof *OriginatorOptionF) String() string { + return oof.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OriginatorOptionF record formatted according to the FormatOptions +func (oof *OriginatorOptionF) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(181) buf.WriteString(oof.tag) - buf.WriteString(oof.PartyIdentifierField(options...)) - buf.WriteString(oof.NameField(options...)) - buf.WriteString(oof.LineOneField(options...)) - buf.WriteString(oof.LineTwoField(options...)) - buf.WriteString(oof.LineThreeField(options...)) + buf.WriteString(oof.FormatPartyIdentifier(options)) + buf.WriteString(oof.FormatName(options)) + buf.WriteString(oof.FormatLineOne(options)) + buf.WriteString(oof.FormatLineTwo(options)) + buf.WriteString(oof.FormatLineThree(options)) - if oof.parseFirstOption(options) { + if options.VariableLengthFields { return oof.stripDelimiters(buf.String()) } else { return buf.String() @@ -212,27 +219,27 @@ func (oof *OriginatorOptionF) fieldInclusion() error { return nil } -// PartyIdentifierField gets a string of the PartyIdentifier field -func (oof *OriginatorOptionF) PartyIdentifierField(options ...bool) string { - return oof.alphaVariableField(oof.PartyIdentifier, 35, oof.parseFirstOption(options)) +// FormatPartyIdentifier returns PartyIdentifier formatted according to the FormatOptions +func (oof *OriginatorOptionF) FormatPartyIdentifier(options FormatOptions) string { + return oof.formatAlphaField(oof.PartyIdentifier, 35, options) } -// NameField gets a string of the Name field -func (oof *OriginatorOptionF) NameField(options ...bool) string { - return oof.alphaVariableField(oof.Name, 35, oof.parseFirstOption(options)) +// FormatName returns Name formatted according to the FormatOptions +func (oof *OriginatorOptionF) FormatName(options FormatOptions) string { + return oof.formatAlphaField(oof.Name, 35, options) } -// LineOneField gets a string of the LineOne field -func (oof *OriginatorOptionF) LineOneField(options ...bool) string { - return oof.alphaVariableField(oof.LineOne, 35, oof.parseFirstOption(options)) +// FormatLineOne returns LineOne formatted according to the FormatOptions +func (oof *OriginatorOptionF) FormatLineOne(options FormatOptions) string { + return oof.formatAlphaField(oof.LineOne, 35, options) } -// LineTwoField gets a string of the LineTwo field -func (oof *OriginatorOptionF) LineTwoField(options ...bool) string { - return oof.alphaVariableField(oof.LineTwo, 35, oof.parseFirstOption(options)) +// FormatLineTwo returns LineTwo formatted according to the FormatOptions +func (oof *OriginatorOptionF) FormatLineTwo(options FormatOptions) string { + return oof.formatAlphaField(oof.LineTwo, 35, options) } -// LineThreeField gets a string of the LineThree field -func (oof *OriginatorOptionF) LineThreeField(options ...bool) string { - return oof.alphaVariableField(oof.LineThree, 35, oof.parseFirstOption(options)) +// FormatLineThree returns LineThree formatted according to the FormatOptions +func (oof *OriginatorOptionF) FormatLineThree(options FormatOptions) string { + return oof.formatAlphaField(oof.LineThree, 35, options) } diff --git a/originatorOptionF_test.go b/originatorOptionF_test.go index b939df90..20edcf37 100644 --- a/originatorOptionF_test.go +++ b/originatorOptionF_test.go @@ -205,7 +205,7 @@ func TestStringOriginatorOptionFVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOriginatorOptionFOptions validates string() with options +// TestStringOriginatorOptionFOptions validates Format() formatted according to the FormatOptions func TestStringOriginatorOptionFOptions(t *testing.T) { var line = "{5010}TXID/123-45-6789*1/Name*" r := NewReader(strings.NewReader(line)) @@ -214,9 +214,8 @@ func TestStringOriginatorOptionFOptions(t *testing.T) { err := r.parseOriginatorOptionF() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OriginatorOptionF.String() - require.Equal(t, str, "{5010}TXID/123-45-6789 1/Name ") - - str = r.currentFEDWireMessage.OriginatorOptionF.String(true) - require.Equal(t, str, "{5010}TXID/123-45-6789*1/Name*") + record := r.currentFEDWireMessage.OriginatorOptionF + require.Equal(t, record.String(), "{5010}TXID/123-45-6789 1/Name ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5010}TXID/123-45-6789*1/Name*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originatorToBeneficiary.go b/originatorToBeneficiary.go index b468abfd..2f74d497 100644 --- a/originatorToBeneficiary.go +++ b/originatorToBeneficiary.go @@ -98,18 +98,25 @@ func (ob *OriginatorToBeneficiary) UnmarshalJSON(data []byte) error { return nil } -// String writes OriginatorToBeneficiary -func (ob *OriginatorToBeneficiary) String(options ...bool) string { +// String returns a fixed-width OriginatorToBeneficiary record +func (ob *OriginatorToBeneficiary) String() string { + return ob.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OriginatorToBeneficiary record formatted according to the FormatOptions +func (ob *OriginatorToBeneficiary) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(146) buf.WriteString(ob.tag) - buf.WriteString(ob.LineOneField(options...)) - buf.WriteString(ob.LineTwoField(options...)) - buf.WriteString(ob.LineThreeField(options...)) - buf.WriteString(ob.LineFourField(options...)) + buf.WriteString(ob.FormatLineOne(options)) + buf.WriteString(ob.FormatLineTwo(options)) + buf.WriteString(ob.FormatLineThree(options)) + buf.WriteString(ob.FormatLineFour(options)) - if ob.parseFirstOption(options) { + if options.VariableLengthFields { return ob.stripDelimiters(buf.String()) } else { return buf.String() @@ -138,22 +145,22 @@ func (ob *OriginatorToBeneficiary) Validate() error { return nil } -// LineOneField gets a string of the LineOne field -func (ob *OriginatorToBeneficiary) LineOneField(options ...bool) string { - return ob.alphaVariableField(ob.LineOne, 35, ob.parseFirstOption(options)) +// FormatLineOne returns LineOne formatted according to the FormatOptions +func (ob *OriginatorToBeneficiary) FormatLineOne(options FormatOptions) string { + return ob.formatAlphaField(ob.LineOne, 35, options) } -// LineTwoField gets a string of the LineTwo field -func (ob *OriginatorToBeneficiary) LineTwoField(options ...bool) string { - return ob.alphaVariableField(ob.LineTwo, 35, ob.parseFirstOption(options)) +// FormatLineTwo returns LineTwo formatted according to the FormatOptions +func (ob *OriginatorToBeneficiary) FormatLineTwo(options FormatOptions) string { + return ob.formatAlphaField(ob.LineTwo, 35, options) } -// LineThreeField gets a string of the LineThree field -func (ob *OriginatorToBeneficiary) LineThreeField(options ...bool) string { - return ob.alphaVariableField(ob.LineThree, 35, ob.parseFirstOption(options)) +// FormatLineThree returns LineThree formatted according to the FormatOptions +func (ob *OriginatorToBeneficiary) FormatLineThree(options FormatOptions) string { + return ob.formatAlphaField(ob.LineThree, 35, options) } -// LineFourField gets a string of the LineFour field -func (ob *OriginatorToBeneficiary) LineFourField(options ...bool) string { - return ob.alphaVariableField(ob.LineFour, 35, ob.parseFirstOption(options)) +// FormatLineFour returns LineFour formatted according to the FormatOptions +func (ob *OriginatorToBeneficiary) FormatLineFour(options FormatOptions) string { + return ob.formatAlphaField(ob.LineFour, 35, options) } diff --git a/originatorToBeneficiary_test.go b/originatorToBeneficiary_test.go index 605514a1..873c5e7b 100644 --- a/originatorToBeneficiary_test.go +++ b/originatorToBeneficiary_test.go @@ -129,7 +129,7 @@ func TestStringOriginatorToBeneficiaryVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOriginatorToBeneficiaryOptions validates string() with options +// TestStringOriginatorToBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringOriginatorToBeneficiaryOptions(t *testing.T) { var line = "{6000}" r := NewReader(strings.NewReader(line)) @@ -138,9 +138,8 @@ func TestStringOriginatorToBeneficiaryOptions(t *testing.T) { err := r.parseOriginatorToBeneficiary() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OriginatorToBeneficiary.String() - require.Equal(t, str, "{6000} ") - - str = r.currentFEDWireMessage.OriginatorToBeneficiary.String(true) - require.Equal(t, str, "{6000}*") + record := r.currentFEDWireMessage.OriginatorToBeneficiary + require.Equal(t, record.String(), "{6000} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6000}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originator_test.go b/originator_test.go index 0527e05a..a852a245 100644 --- a/originator_test.go +++ b/originator_test.go @@ -174,7 +174,7 @@ func TestStringOriginatorVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOriginatorOptions validates string() with options +// TestStringOriginatorOptions validates Format() formatted according to the FormatOptions func TestStringOriginatorOptions(t *testing.T) { var line = "{5000}B1*" r := NewReader(strings.NewReader(line)) @@ -183,9 +183,8 @@ func TestStringOriginatorOptions(t *testing.T) { err := r.parseOriginator() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.Originator.String() - require.Equal(t, str, "{5000}B1 ") - - str = r.currentFEDWireMessage.Originator.String(true) - require.Equal(t, str, "{5000}B1*") + record := r.currentFEDWireMessage.Originator + require.Equal(t, record.String(), "{5000}B1 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5000}B1*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/outputMessageAccountabilityData.go b/outputMessageAccountabilityData.go index e2757115..e6c90e1d 100644 --- a/outputMessageAccountabilityData.go +++ b/outputMessageAccountabilityData.go @@ -116,20 +116,27 @@ func (omad *OutputMessageAccountabilityData) UnmarshalJSON(data []byte) error { return nil } -// String writes OutputMessageAccountabilityData -func (omad *OutputMessageAccountabilityData) String(options ...bool) string { +// String returns a fixed-width OutputMessageAccountabilityData record +func (omad *OutputMessageAccountabilityData) String() string { + return omad.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a OutputMessageAccountabilityData record formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(40) buf.WriteString(omad.tag) - buf.WriteString(omad.OutputCycleDateField(options...)) - buf.WriteString(omad.OutputDestinationIDField(options...)) + buf.WriteString(omad.FormatOutputCycleDate(options)) + buf.WriteString(omad.FormatOutputDestinationID(options)) buf.WriteString(omad.OutputSequenceNumberField()) - buf.WriteString(omad.OutputDateField(options...)) - buf.WriteString(omad.OutputTimeField(options...)) - buf.WriteString(omad.OutputFRBApplicationIdentificationField(options...)) + buf.WriteString(omad.FormatOutputDate(options)) + buf.WriteString(omad.FormatOutputTime(options)) + buf.WriteString(omad.FormatOutputFRBApplicationIdentification(options)) - if omad.parseFirstOption(options) { + if options.VariableLengthFields { return omad.stripDelimiters(buf.String()) } else { return buf.String() @@ -146,14 +153,14 @@ func (omad *OutputMessageAccountabilityData) Validate() error { return nil } -// OutputCycleDateField gets a string of the OutputCycleDate field -func (omad *OutputMessageAccountabilityData) OutputCycleDateField(options ...bool) string { - return omad.alphaVariableField(omad.OutputCycleDate, 8, omad.parseFirstOption(options)) +// FormatOutputCycleDate returns OutputCycleDate formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) FormatOutputCycleDate(options FormatOptions) string { + return omad.formatAlphaField(omad.OutputCycleDate, 8, options) } -// OutputDestinationIDField gets a string of the OutputDestinationID field -func (omad *OutputMessageAccountabilityData) OutputDestinationIDField(options ...bool) string { - return omad.alphaVariableField(omad.OutputDestinationID, 8, omad.parseFirstOption(options)) +// FormatOutputDestinationID returns OutputDestinationID formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) FormatOutputDestinationID(options FormatOptions) string { + return omad.formatAlphaField(omad.OutputDestinationID, 8, options) } // OutputSequenceNumberField gets a string of the OutputSequenceNumber field @@ -161,17 +168,17 @@ func (omad *OutputMessageAccountabilityData) OutputSequenceNumberField() string return omad.numericStringField(omad.OutputSequenceNumber, 6) } -// OutputDateField gets a string of the OutputDate field -func (omad *OutputMessageAccountabilityData) OutputDateField(options ...bool) string { - return omad.alphaVariableField(omad.OutputDate, 4, omad.parseFirstOption(options)) +// FormatOutputDate returns OutputDate formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) FormatOutputDate(options FormatOptions) string { + return omad.formatAlphaField(omad.OutputDate, 4, options) } -// OutputTimeField gets a string of the OutputTime field -func (omad *OutputMessageAccountabilityData) OutputTimeField(options ...bool) string { - return omad.alphaVariableField(omad.OutputTime, 4, omad.parseFirstOption(options)) +// FormatOutputTime returns OutputTime formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) FormatOutputTime(options FormatOptions) string { + return omad.formatAlphaField(omad.OutputTime, 4, options) } -// OutputFRBApplicationIdentificationField gets a string of the OutputFRBApplicationIdentification field -func (omad *OutputMessageAccountabilityData) OutputFRBApplicationIdentificationField(options ...bool) string { - return omad.alphaVariableField(omad.OutputFRBApplicationIdentification, 4, omad.parseFirstOption(options)) +// FormatOutputFRBApplicationIdentification returns OutputFRBApplicationIdentification formatted according to the FormatOptions +func (omad *OutputMessageAccountabilityData) FormatOutputFRBApplicationIdentification(options FormatOptions) string { + return omad.formatAlphaField(omad.OutputFRBApplicationIdentification, 4, options) } diff --git a/outputMessageAccountabilityData_test.go b/outputMessageAccountabilityData_test.go index 139add83..0a1b5b66 100644 --- a/outputMessageAccountabilityData_test.go +++ b/outputMessageAccountabilityData_test.go @@ -94,7 +94,7 @@ func TestStringOutputMessageAccountabilityDataVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringOutputMessageAccountabilityDataOptions validates string() with options +// TestStringOutputMessageAccountabilityDataOptions validates Format() formatted according to the FormatOptions func TestStringOutputMessageAccountabilityDataOptions(t *testing.T) { var line = "{1120}**000001" r := NewReader(strings.NewReader(line)) @@ -103,9 +103,8 @@ func TestStringOutputMessageAccountabilityDataOptions(t *testing.T) { err := r.parseOutputMessageAccountabilityData() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.OutputMessageAccountabilityData.String() - require.Equal(t, str, "{1120} 000001 ") - - str = r.currentFEDWireMessage.OutputMessageAccountabilityData.String(true) - require.Equal(t, str, "{1120}**000001*") + record := r.currentFEDWireMessage.OutputMessageAccountabilityData + require.Equal(t, record.String(), "{1120} 000001 ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1120}**000001*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/paymentNotification.go b/paymentNotification.go index 3ae81d15..59fdf6eb 100644 --- a/paymentNotification.go +++ b/paymentNotification.go @@ -127,21 +127,28 @@ func (pn *PaymentNotification) UnmarshalJSON(data []byte) error { return nil } -// String writes PaymentNotification -func (pn *PaymentNotification) String(options ...bool) string { +// String returns a fixed-width PaymentNotification record +func (pn *PaymentNotification) String() string { + return pn.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a PaymentNotification record formatted according to the FormatOptions +func (pn *PaymentNotification) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(2335) buf.WriteString(pn.tag) - buf.WriteString(pn.PaymentNotificationIndicatorField(options...)) - buf.WriteString(pn.ContactNotificationElectronicAddressField(options...)) - buf.WriteString(pn.ContactNameField(options...)) - buf.WriteString(pn.ContactPhoneNumberField(options...)) - buf.WriteString(pn.ContactMobileNumberField(options...)) - buf.WriteString(pn.ContactFaxNumberField(options...)) - buf.WriteString(pn.EndToEndIdentificationField(options...)) - - if pn.parseFirstOption(options) { + buf.WriteString(pn.FormatPaymentNotificationIndicator(options)) + buf.WriteString(pn.FormatContactNotificationElectronicAddress(options)) + buf.WriteString(pn.FormatContactName(options)) + buf.WriteString(pn.FormatContactPhoneNumber(options)) + buf.WriteString(pn.FormatContactMobileNumber(options)) + buf.WriteString(pn.FormatContactFaxNumber(options)) + buf.WriteString(pn.FormatEndToEndIdentification(options)) + + if options.VariableLengthFields { return pn.stripDelimiters(buf.String()) } else { return buf.String() @@ -179,36 +186,36 @@ func (pn *PaymentNotification) Validate() error { } // PaymentNotificationIndicatorField gets a string of PaymentNotificationIndicator field -func (pn *PaymentNotification) PaymentNotificationIndicatorField(options ...bool) string { - return pn.alphaVariableField(pn.PaymentNotificationIndicator, 1, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatPaymentNotificationIndicator(options FormatOptions) string { + return pn.formatAlphaField(pn.PaymentNotificationIndicator, 1, options) } // ContactNotificationElectronicAddressField gets a string of ContactNotificationElectronicAddress field -func (pn *PaymentNotification) ContactNotificationElectronicAddressField(options ...bool) string { - return pn.alphaVariableField(pn.ContactNotificationElectronicAddress, 2048, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatContactNotificationElectronicAddress(options FormatOptions) string { + return pn.formatAlphaField(pn.ContactNotificationElectronicAddress, 2048, options) } // ContactNameField gets a string of ContactName field -func (pn *PaymentNotification) ContactNameField(options ...bool) string { - return pn.alphaVariableField(pn.ContactName, 140, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatContactName(options FormatOptions) string { + return pn.formatAlphaField(pn.ContactName, 140, options) } // ContactPhoneNumberField gets a string of ContactPhoneNumberField field -func (pn *PaymentNotification) ContactPhoneNumberField(options ...bool) string { - return pn.alphaVariableField(pn.ContactPhoneNumber, 35, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatContactPhoneNumber(options FormatOptions) string { + return pn.formatAlphaField(pn.ContactPhoneNumber, 35, options) } // ContactMobileNumberField gets a string of ContactMobileNumber field -func (pn *PaymentNotification) ContactMobileNumberField(options ...bool) string { - return pn.alphaVariableField(pn.ContactMobileNumber, 35, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatContactMobileNumber(options FormatOptions) string { + return pn.formatAlphaField(pn.ContactMobileNumber, 35, options) } // ContactFaxNumberField gets a string of FaxNumber field -func (pn *PaymentNotification) ContactFaxNumberField(options ...bool) string { - return pn.alphaVariableField(pn.ContactFaxNumber, 35, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatContactFaxNumber(options FormatOptions) string { + return pn.formatAlphaField(pn.ContactFaxNumber, 35, options) } // EndToEndIdentificationField gets a string of EndToEndIdentification field -func (pn *PaymentNotification) EndToEndIdentificationField(options ...bool) string { - return pn.alphaVariableField(pn.EndToEndIdentification, 35, pn.parseFirstOption(options)) +func (pn *PaymentNotification) FormatEndToEndIdentification(options FormatOptions) string { + return pn.formatAlphaField(pn.EndToEndIdentification, 35, options) } diff --git a/paymentNotification_test.go b/paymentNotification_test.go index 45443c22..35dd6ac1 100644 --- a/paymentNotification_test.go +++ b/paymentNotification_test.go @@ -162,7 +162,7 @@ func TestStringPaymentNotificationVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringPaymentNotificationOptions validates string() with options +// TestStringPaymentNotificationOptions validates Format() formatted according to the FormatOptions func TestStringPaymentNotificationOptions(t *testing.T) { var line = "{3620}" r := NewReader(strings.NewReader(line)) @@ -171,9 +171,8 @@ func TestStringPaymentNotificationOptions(t *testing.T) { err := r.parsePaymentNotification() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.PaymentNotification.String() - require.Equal(t, str, "{3620} ") - - str = r.currentFEDWireMessage.PaymentNotification.String(true) - require.Equal(t, str, "{3620}*") + record := r.currentFEDWireMessage.PaymentNotification + require.Equal(t, record.String(), "{3620} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3620}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/previousMessageIdentifier.go b/previousMessageIdentifier.go index dc38f31a..ecd41286 100644 --- a/previousMessageIdentifier.go +++ b/previousMessageIdentifier.go @@ -71,13 +71,20 @@ func (pmi *PreviousMessageIdentifier) UnmarshalJSON(data []byte) error { return nil } -// String writes PreviousMessageIdentifier -func (pmi *PreviousMessageIdentifier) String(options ...bool) string { +// String returns a fixed-width PreviousMessageIdentifier record +func (pmi *PreviousMessageIdentifier) String() string { + return pmi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a PreviousMessageIdentifier record formatted according to the FormatOptions +func (pmi *PreviousMessageIdentifier) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(28) buf.WriteString(pmi.tag) - buf.WriteString(pmi.PreviousMessageIdentifierField(options...)) + buf.WriteString(pmi.FormatPreviousMessageIdentifier(options)) return buf.String() } @@ -95,6 +102,11 @@ func (pmi *PreviousMessageIdentifier) Validate() error { } // PreviousMessageIdentifierField gets a string of PreviousMessageIdentifier field -func (pmi *PreviousMessageIdentifier) PreviousMessageIdentifierField(options ...bool) string { - return pmi.alphaVariableField(pmi.PreviousMessageIdentifier, 22, pmi.parseFirstOption(options)) +func (pmi *PreviousMessageIdentifier) PreviousMessageIdentifierField() string { + return pmi.alphaField(pmi.PreviousMessageIdentifier, 22) +} + +// FormatPreviousMessageIdentifier returns PreviousMessageIdentifier formatted according to the FormatOptions +func (pmi *PreviousMessageIdentifier) FormatPreviousMessageIdentifier(options FormatOptions) string { + return pmi.formatAlphaField(pmi.PreviousMessageIdentifier, 22, options) } diff --git a/previousMessageIdentifier_test.go b/previousMessageIdentifier_test.go index 907ccf25..7f9f556d 100644 --- a/previousMessageIdentifier_test.go +++ b/previousMessageIdentifier_test.go @@ -96,7 +96,7 @@ func TestStringPreviousMessageIdentifierVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringPreviousMessageIdentifierOptions validates string() with options +// TestStringPreviousMessageIdentifierOptions validates Format() formatted according to the FormatOptions func TestStringPreviousMessageIdentifierOptions(t *testing.T) { var line = "{3500}" r := NewReader(strings.NewReader(line)) @@ -105,9 +105,8 @@ func TestStringPreviousMessageIdentifierOptions(t *testing.T) { err := r.parsePreviousMessageIdentifier() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.PreviousMessageIdentifier.String() - require.Equal(t, str, "{3500} ") - - str = r.currentFEDWireMessage.PreviousMessageIdentifier.String(true) - require.Equal(t, str, "{3500}*") + record := r.currentFEDWireMessage.PreviousMessageIdentifier + require.Equal(t, record.String(), "{3500} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3500}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/primaryRemittanceDocument.go b/primaryRemittanceDocument.go index 37df57b3..85743eae 100644 --- a/primaryRemittanceDocument.go +++ b/primaryRemittanceDocument.go @@ -92,18 +92,25 @@ func (prd *PrimaryRemittanceDocument) UnmarshalJSON(data []byte) error { return nil } -// String writes PrimaryRemittanceDocument -func (prd *PrimaryRemittanceDocument) String(options ...bool) string { +// String returns a fixed-width PrimaryRemittanceDocument record +func (prd *PrimaryRemittanceDocument) String() string { + return prd.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a PrimaryRemittanceDocument record formatted according to the FormatOptions +func (prd *PrimaryRemittanceDocument) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(115) buf.WriteString(prd.tag) buf.WriteString(prd.DocumentTypeCodeField()) - buf.WriteString(prd.ProprietaryDocumentTypeCodeField(options...)) - buf.WriteString(prd.DocumentIdentificationNumberField(options...)) - buf.WriteString(prd.IssuerField(options...)) + buf.WriteString(prd.FormatProprietaryDocumentTypeCode(options)) + buf.WriteString(prd.FormatDocumentIdentificationNumber(options)) + buf.WriteString(prd.FormatIssuer(options)) - if prd.parseFirstOption(options) { + if options.VariableLengthFields { return prd.stripDelimiters(buf.String()) } else { return buf.String() @@ -161,16 +168,31 @@ func (prd *PrimaryRemittanceDocument) DocumentTypeCodeField() string { } // ProprietaryDocumentTypeCodeField gets a string of the ProprietaryDocumentTypeCode field -func (prd *PrimaryRemittanceDocument) ProprietaryDocumentTypeCodeField(options ...bool) string { - return prd.alphaVariableField(prd.ProprietaryDocumentTypeCode, 35, prd.parseFirstOption(options)) +func (prd *PrimaryRemittanceDocument) ProprietaryDocumentTypeCodeField() string { + return prd.alphaField(prd.ProprietaryDocumentTypeCode, 35) } // DocumentIdentificationNumberField gets a string of the DocumentIdentificationNumber field -func (prd *PrimaryRemittanceDocument) DocumentIdentificationNumberField(options ...bool) string { - return prd.alphaVariableField(prd.DocumentIdentificationNumber, 35, prd.parseFirstOption(options)) +func (prd *PrimaryRemittanceDocument) DocumentIdentificationNumberField() string { + return prd.alphaField(prd.DocumentIdentificationNumber, 35) } // IssuerField gets a string of the Issuer field -func (prd *PrimaryRemittanceDocument) IssuerField(options ...bool) string { - return prd.alphaVariableField(prd.Issuer, 35, prd.parseFirstOption(options)) +func (prd *PrimaryRemittanceDocument) IssuerField() string { + return prd.alphaField(prd.Issuer, 35) +} + +// FormatProprietaryDocumentTypeCode returns ProprietaryDocumentTypeCode formatted according to the FormatOptions +func (prd *PrimaryRemittanceDocument) FormatProprietaryDocumentTypeCode(options FormatOptions) string { + return prd.formatAlphaField(prd.ProprietaryDocumentTypeCode, 35, options) +} + +// FormatDocumentIdentificationNumber returns DocumentIdentificationNumber formatted according to the FormatOptions +func (prd *PrimaryRemittanceDocument) FormatDocumentIdentificationNumber(options FormatOptions) string { + return prd.formatAlphaField(prd.DocumentIdentificationNumber, 35, options) +} + +// FormatIssuer returns Issuer formatted according to the FormatOptions +func (prd *PrimaryRemittanceDocument) FormatIssuer(options FormatOptions) string { + return prd.formatAlphaField(prd.Issuer, 35, options) } diff --git a/primaryRemittanceDocument_test.go b/primaryRemittanceDocument_test.go index 166f245b..48bf42f2 100644 --- a/primaryRemittanceDocument_test.go +++ b/primaryRemittanceDocument_test.go @@ -162,7 +162,7 @@ func TestStringPrimaryRemittanceDocumentVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringPrimaryRemittanceDocumentOptions validates string() with options +// TestStringPrimaryRemittanceDocumentOptions validates Format() formatted according to the FormatOptions func TestStringPrimaryRemittanceDocumentOptions(t *testing.T) { var line = "{8400}AROI*Issuer*" r := NewReader(strings.NewReader(line)) @@ -171,9 +171,8 @@ func TestStringPrimaryRemittanceDocumentOptions(t *testing.T) { err := r.parsePrimaryRemittanceDocument() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.PrimaryRemittanceDocument.String() - require.Equal(t, str, "{8400}AROI Issuer ") - - str = r.currentFEDWireMessage.PrimaryRemittanceDocument.String(true) - require.Equal(t, str, "{8400}AROI*Issuer*") + record := r.currentFEDWireMessage.PrimaryRemittanceDocument + require.Equal(t, record.String(), "{8400}AROI Issuer ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8400}AROI*Issuer*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/receiptTimeStamp.go b/receiptTimeStamp.go index ffd47278..1aec0e0c 100644 --- a/receiptTimeStamp.go +++ b/receiptTimeStamp.go @@ -89,17 +89,24 @@ func (rts *ReceiptTimeStamp) UnmarshalJSON(data []byte) error { return nil } -// String writes ReceiptTimeStamp -func (rts *ReceiptTimeStamp) String(options ...bool) string { +// String returns a fixed-width ReceiptTimeStamp record +func (rts *ReceiptTimeStamp) String() string { + return rts.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a ReceiptTimeStamp record formatted according to the FormatOptions +func (rts *ReceiptTimeStamp) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(18) buf.WriteString(rts.tag) - buf.WriteString(rts.ReceiptDateField(options...)) - buf.WriteString(rts.ReceiptTimeField(options...)) - buf.WriteString(rts.ReceiptApplicationIdentificationField(options...)) + buf.WriteString(rts.FormatReceiptDate(options)) + buf.WriteString(rts.FormatReceiptTime(options)) + buf.WriteString(rts.FormatReceiptApplicationIdentification(options)) - if rts.parseFirstOption(options) { + if options.VariableLengthFields { return rts.stripDelimiters(buf.String()) } else { return buf.String() @@ -117,16 +124,31 @@ func (rts *ReceiptTimeStamp) Validate() error { } // ReceiptDateField gets a string of the ReceiptDate field -func (rts *ReceiptTimeStamp) ReceiptDateField(options ...bool) string { - return rts.alphaVariableField(rts.ReceiptDate, 4, rts.parseFirstOption(options)) +func (rts *ReceiptTimeStamp) ReceiptDateField() string { + return rts.alphaField(rts.ReceiptDate, 4) } // ReceiptTimeField gets a string of the ReceiptTime field -func (rts *ReceiptTimeStamp) ReceiptTimeField(options ...bool) string { - return rts.alphaVariableField(rts.ReceiptTime, 4, rts.parseFirstOption(options)) +func (rts *ReceiptTimeStamp) ReceiptTimeField() string { + return rts.alphaField(rts.ReceiptTime, 4) } // ReceiptApplicationIdentificationField gets a string of the ReceiptApplicationIdentification field -func (rts *ReceiptTimeStamp) ReceiptApplicationIdentificationField(options ...bool) string { - return rts.alphaVariableField(rts.ReceiptApplicationIdentification, 4, rts.parseFirstOption(options)) +func (rts *ReceiptTimeStamp) ReceiptApplicationIdentificationField() string { + return rts.alphaField(rts.ReceiptApplicationIdentification, 4) +} + +// FormatReceiptDate returns ReceiptDate formatted according to the FormatOptions +func (rts *ReceiptTimeStamp) FormatReceiptDate(options FormatOptions) string { + return rts.formatAlphaField(rts.ReceiptDate, 4, options) +} + +// FormatReceiptTime returns ReceiptTime formatted according to the FormatOptions +func (rts *ReceiptTimeStamp) FormatReceiptTime(options FormatOptions) string { + return rts.formatAlphaField(rts.ReceiptTime, 4, options) +} + +// FormatReceiptApplicationIdentification returns ReceiptApplicationIdentification formatted according to the FormatOptions +func (rts *ReceiptTimeStamp) FormatReceiptApplicationIdentification(options FormatOptions) string { + return rts.formatAlphaField(rts.ReceiptApplicationIdentification, 4, options) } diff --git a/receiptTimeStamp_test.go b/receiptTimeStamp_test.go index 32aee851..e2ba40eb 100644 --- a/receiptTimeStamp_test.go +++ b/receiptTimeStamp_test.go @@ -88,7 +88,7 @@ func TestStringReceiptTimeStampVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringReceiptTimeStampOptions validates string() with options +// TestStringReceiptTimeStampOptions validates Format() formatted according to the FormatOptions func TestStringReceiptTimeStampOptions(t *testing.T) { var line = "{1110}" r := NewReader(strings.NewReader(line)) @@ -97,9 +97,8 @@ func TestStringReceiptTimeStampOptions(t *testing.T) { err := r.parseReceiptTimeStamp() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ReceiptTimeStamp.String() - require.Equal(t, str, "{1110} ") - - str = r.currentFEDWireMessage.ReceiptTimeStamp.String(true) - require.Equal(t, str, "{1110}*") + record := r.currentFEDWireMessage.ReceiptTimeStamp + require.Equal(t, record.String(), "{1110} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1110}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/receiverDepositoryInstitution.go b/receiverDepositoryInstitution.go index 32cdce39..e2180cce 100644 --- a/receiverDepositoryInstitution.go +++ b/receiverDepositoryInstitution.go @@ -80,14 +80,21 @@ func (rdi *ReceiverDepositoryInstitution) UnmarshalJSON(data []byte) error { return nil } -// String writes ReceiverDepositoryInstitution -func (rdi *ReceiverDepositoryInstitution) String(options ...bool) string { +// String returns a fixed-width ReceiverDepositoryInstitution record +func (rdi *ReceiverDepositoryInstitution) String() string { + return rdi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a ReceiverDepositoryInstitution record formatted according to the FormatOptions +func (rdi *ReceiverDepositoryInstitution) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(33) buf.WriteString(rdi.tag) - buf.WriteString(rdi.ReceiverABANumberField(options...)) - buf.WriteString(rdi.ReceiverShortNameField(options...)) + buf.WriteString(rdi.FormatReceiverABANumber(options)) + buf.WriteString(rdi.FormatReceiverShortName(options)) return buf.String() } @@ -123,11 +130,21 @@ func (rdi *ReceiverDepositoryInstitution) fieldInclusion() error { } // ReceiverABANumberField gets a string of the ReceiverABANumber field -func (rdi *ReceiverDepositoryInstitution) ReceiverABANumberField(options ...bool) string { - return rdi.alphaVariableField(rdi.ReceiverABANumber, 9, rdi.parseFirstOption(options)) +func (rdi *ReceiverDepositoryInstitution) ReceiverABANumberField() string { + return rdi.alphaField(rdi.ReceiverABANumber, 9) } // ReceiverShortNameField gets a string of the ReceiverShortName field -func (rdi *ReceiverDepositoryInstitution) ReceiverShortNameField(options ...bool) string { - return rdi.alphaVariableField(rdi.ReceiverShortName, 18, rdi.parseFirstOption(options)) +func (rdi *ReceiverDepositoryInstitution) ReceiverShortNameField() string { + return rdi.alphaField(rdi.ReceiverShortName, 18) +} + +// FormatReceiverABANumber returns ReceiverABANumber formatted according to the FormatOptions +func (rdi *ReceiverDepositoryInstitution) FormatReceiverABANumber(options FormatOptions) string { + return rdi.formatAlphaField(rdi.ReceiverABANumber, 9, options) +} + +// FormatReceiverShortName returns ReceiverShortName formatted according to the FormatOptions +func (rdi *ReceiverDepositoryInstitution) FormatReceiverShortName(options FormatOptions) string { + return rdi.formatAlphaField(rdi.ReceiverShortName, 18, options) } diff --git a/receiverDepositoryInstitution_test.go b/receiverDepositoryInstitution_test.go index b85f6fa3..b6c4fd36 100644 --- a/receiverDepositoryInstitution_test.go +++ b/receiverDepositoryInstitution_test.go @@ -127,7 +127,7 @@ func TestStringReceiverDepositoryInstitutionVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringReceiverDepositoryInstitutionOptions validates string() with options +// TestStringReceiverDepositoryInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { var line = "{3400}1*A*" r := NewReader(strings.NewReader(line)) @@ -136,9 +136,8 @@ func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { err := r.parseReceiverDepositoryInstitution() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ReceiverDepositoryInstitution.String() - require.Equal(t, str, "{3400}1 A ") - - str = r.currentFEDWireMessage.ReceiverDepositoryInstitution.String(true) - require.Equal(t, str, "{3400}1*A*") + record := r.currentFEDWireMessage.ReceiverDepositoryInstitution + require.Equal(t, record.String(), "{3400}1 A ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}1*A*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/relatedRemittance.go b/relatedRemittance.go index 10adb083..40630107 100644 --- a/relatedRemittance.go +++ b/relatedRemittance.go @@ -210,34 +210,41 @@ func (rr *RelatedRemittance) UnmarshalJSON(data []byte) error { return nil } -// String writes RelatedRemittance -func (rr *RelatedRemittance) String(options ...bool) string { +// String returns a fixed-width RelatedRemittance record +func (rr *RelatedRemittance) String() string { + return rr.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a RelatedRemittance record formatted according to the FormatOptions +func (rr *RelatedRemittance) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(3041) buf.WriteString(rr.tag) - buf.WriteString(rr.RemittanceIdentificationField(options...)) - buf.WriteString(rr.RemittanceLocationMethodField(options...)) - buf.WriteString(rr.RemittanceLocationElectronicAddressField(options...)) - buf.WriteString(rr.NameField(options...)) - buf.WriteString(rr.AddressTypeField(options...)) - buf.WriteString(rr.DepartmentField(options...)) - buf.WriteString(rr.SubDepartmentField(options...)) - buf.WriteString(rr.StreetNameField(options...)) - buf.WriteString(rr.BuildingNumberField(options...)) - buf.WriteString(rr.PostCodeField(options...)) - buf.WriteString(rr.TownNameField(options...)) - buf.WriteString(rr.CountrySubDivisionStateField(options...)) - buf.WriteString(rr.CountryField(options...)) - buf.WriteString(rr.AddressLineOneField(options...)) - buf.WriteString(rr.AddressLineTwoField(options...)) - buf.WriteString(rr.AddressLineThreeField(options...)) - buf.WriteString(rr.AddressLineFourField(options...)) - buf.WriteString(rr.AddressLineFiveField(options...)) - buf.WriteString(rr.AddressLineSixField(options...)) - buf.WriteString(rr.AddressLineSevenField(options...)) - - if rr.parseFirstOption(options) { + buf.WriteString(rr.FormatRemittanceIdentification(options)) + buf.WriteString(rr.FormatRemittanceLocationMethod(options)) + buf.WriteString(rr.FormatRemittanceLocationElectronicAddress(options)) + buf.WriteString(rr.FormatName(options)) + buf.WriteString(rr.FormatAddressType(options)) + buf.WriteString(rr.FormatDepartment(options)) + buf.WriteString(rr.FormatSubDepartment(options)) + buf.WriteString(rr.FormatStreetName(options)) + buf.WriteString(rr.FormatBuildingNumber(options)) + buf.WriteString(rr.FormatPostCode(options)) + buf.WriteString(rr.FormatTownName(options)) + buf.WriteString(rr.FormatCountrySubDivisionState(options)) + buf.WriteString(rr.FormatCountry(options)) + buf.WriteString(rr.FormatAddressLineOne(options)) + buf.WriteString(rr.FormatAddressLineTwo(options)) + buf.WriteString(rr.FormatAddressLineThree(options)) + buf.WriteString(rr.FormatAddressLineFour(options)) + buf.WriteString(rr.FormatAddressLineFive(options)) + buf.WriteString(rr.FormatAddressLineSix(options)) + buf.WriteString(rr.FormatAddressLineSeven(options)) + + if options.VariableLengthFields { return rr.stripDelimiters(buf.String()) } else { return buf.String() @@ -329,101 +336,201 @@ func (rr *RelatedRemittance) fieldInclusion() error { } // RemittanceIdentificationField gets a string of the RemittanceIdentification field -func (rr *RelatedRemittance) RemittanceIdentificationField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceIdentification, 35, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) RemittanceIdentificationField() string { + return rr.alphaField(rr.RemittanceIdentification, 35) } // RemittanceLocationMethodField gets a string of the RemittanceLocationMethod field -func (rr *RelatedRemittance) RemittanceLocationMethodField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceLocationMethod, 4, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) RemittanceLocationMethodField() string { + return rr.alphaField(rr.RemittanceLocationMethod, 4) } // RemittanceLocationElectronicAddressField gets a string of the RemittanceLocationElectronicAddress field -func (rr *RelatedRemittance) RemittanceLocationElectronicAddressField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceLocationElectronicAddress, 2048, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) RemittanceLocationElectronicAddressField() string { + return rr.alphaField(rr.RemittanceLocationElectronicAddress, 2048) } // NameField gets a string of the Name field -func (rr *RelatedRemittance) NameField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.Name, 140, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) NameField() string { + return rr.alphaField(rr.RemittanceData.Name, 140) } // AddressTypeField gets a string of the AddressType field -func (rr *RelatedRemittance) AddressTypeField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressType, 4, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressTypeField() string { + return rr.alphaField(rr.RemittanceData.AddressType, 4) } // DepartmentField gets a string of the Department field -func (rr *RelatedRemittance) DepartmentField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.Department, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) DepartmentField() string { + return rr.alphaField(rr.RemittanceData.Department, 70) } // SubDepartmentField gets a string of the SubDepartment field -func (rr *RelatedRemittance) SubDepartmentField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.SubDepartment, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) SubDepartmentField() string { + return rr.alphaField(rr.RemittanceData.SubDepartment, 70) } // StreetNameField gets a string of the StreetName field -func (rr *RelatedRemittance) StreetNameField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.StreetName, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) StreetNameField() string { + return rr.alphaField(rr.RemittanceData.StreetName, 70) } // BuildingNumberField gets a string of the BuildingNumber field -func (rr *RelatedRemittance) BuildingNumberField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.BuildingNumber, 16, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) BuildingNumberField() string { + return rr.alphaField(rr.RemittanceData.BuildingNumber, 16) } // PostCodeField gets a string of the PostCode field -func (rr *RelatedRemittance) PostCodeField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.PostCode, 16, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) PostCodeField() string { + return rr.alphaField(rr.RemittanceData.PostCode, 16) } // TownNameField gets a string of the TownName field -func (rr *RelatedRemittance) TownNameField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.TownName, 35, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) TownNameField() string { + return rr.alphaField(rr.RemittanceData.TownName, 35) } // CountrySubDivisionStateField gets a string of the CountrySubDivisionState field -func (rr *RelatedRemittance) CountrySubDivisionStateField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.CountrySubDivisionState, 35, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) CountrySubDivisionStateField() string { + return rr.alphaField(rr.RemittanceData.CountrySubDivisionState, 35) } // CountryField gets a string of the Country field -func (rr *RelatedRemittance) CountryField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.Country, 2, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) CountryField() string { + return rr.alphaField(rr.RemittanceData.Country, 2) } // AddressLineOneField gets a string of the AddressLineOne field -func (rr *RelatedRemittance) AddressLineOneField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineOne, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineOneField() string { + return rr.alphaField(rr.RemittanceData.AddressLineOne, 70) } // AddressLineTwoField gets a string of the AddressLineTwo field -func (rr *RelatedRemittance) AddressLineTwoField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineTwo, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineTwoField() string { + return rr.alphaField(rr.RemittanceData.AddressLineTwo, 70) } // AddressLineThreeField gets a string of the AddressLineThree field -func (rr *RelatedRemittance) AddressLineThreeField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineThree, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineThreeField() string { + return rr.alphaField(rr.RemittanceData.AddressLineThree, 70) } // AddressLineFourField gets a string of the AddressLineFour field -func (rr *RelatedRemittance) AddressLineFourField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineFour, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineFourField() string { + return rr.alphaField(rr.RemittanceData.AddressLineFour, 70) } // AddressLineFiveField gets a string of the AddressLineFive field -func (rr *RelatedRemittance) AddressLineFiveField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineFive, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineFiveField() string { + return rr.alphaField(rr.RemittanceData.AddressLineFive, 70) } // AddressLineSixField gets a string of the AddressLineSix field -func (rr *RelatedRemittance) AddressLineSixField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineSix, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineSixField() string { + return rr.alphaField(rr.RemittanceData.AddressLineSix, 70) } // AddressLineSevenField gets a string of the AddressLineSeven field -func (rr *RelatedRemittance) AddressLineSevenField(options ...bool) string { - return rr.alphaVariableField(rr.RemittanceData.AddressLineSeven, 70, rr.parseFirstOption(options)) +func (rr *RelatedRemittance) AddressLineSevenField() string { + return rr.alphaField(rr.RemittanceData.AddressLineSeven, 70) +} + +// FormatRemittanceIdentification returns rr.RemittanceIdentification formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatRemittanceIdentification(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceIdentification, 35, options) +} + +// FormatRemittanceLocationMethod returns rr.RemittanceLocationMethod formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatRemittanceLocationMethod(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceLocationMethod, 4, options) +} + +// FormatRemittanceLocationElectronicAddress returns rr.RemittanceLocationElectronicAddress formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatRemittanceLocationElectronicAddress(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceLocationElectronicAddress, 2048, options) +} + +// FormatName returns RemittanceData.Name formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatName(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.Name, 140, options) +} + +// FormatAddressType returns RemittanceData.AddressType formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressType(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressType, 4, options) +} + +// FormatDepartment returns RemittanceData.Department formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatDepartment(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.Department, 70, options) +} + +// FormatSubDepartment returns RemittanceData.SubDepartment formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatSubDepartment(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.SubDepartment, 70, options) +} + +// FormatStreetName returns RemittanceData.StreetName formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatStreetName(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.StreetName, 70, options) +} + +// FormatBuildingNumber returns RemittanceData.BuildingNumber formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatBuildingNumber(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.BuildingNumber, 16, options) +} + +// FormatPostCode returns RemittanceData.PostCode formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatPostCode(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.PostCode, 16, options) +} + +// FormatTownName returns RemittanceData.TownName formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatTownName(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.TownName, 35, options) +} + +// FormatCountrySubDivisionState returns RemittanceData.CountrySubDivisionState formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatCountrySubDivisionState(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.CountrySubDivisionState, 35, options) +} + +// FormatCountry returns RemittanceData.Country formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatCountry(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.Country, 2, options) +} + +// FormatAddressLineOne returns RemittanceData.AddressLineOne formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineOne(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineOne, 70, options) +} + +// FormatAddressLineTwo returns RemittanceData.AddressLineTwo formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineTwo(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineTwo, 70, options) +} + +// FormatAddressLineThree returns RemittanceData.AddressLineThree formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineThree(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineThree, 70, options) +} + +// FormatAddressLineFour returns RemittanceData.AddressLineFour formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineFour(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineFour, 70, options) +} + +// FormatAddressLineFive returns RemittanceData.AddressLineFive formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineFive(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineFive, 70, options) +} + +// FormatAddressLineSix returns RemittanceData.AddressLineSix formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineSix(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineSix, 70, options) +} + +// FormatAddressLineSeven returns RemittanceData.AddressLineSeven formatted according to the FormatOptions +func (rr *RelatedRemittance) FormatAddressLineSeven(options FormatOptions) string { + return rr.formatAlphaField(rr.RemittanceData.AddressLineSeven, 70, options) } diff --git a/relatedRemittance_test.go b/relatedRemittance_test.go index 41db9421..15d86d85 100644 --- a/relatedRemittance_test.go +++ b/relatedRemittance_test.go @@ -316,7 +316,7 @@ func TestStringRelatedRemittanceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringRelatedRemittanceOptions validates string() with options +// TestStringRelatedRemittanceOptions validates Format() formatted according to the FormatOptions func TestStringRelatedRemittanceOptions(t *testing.T) { var line = "{8250}*EDIC*A*ADDR*" r := NewReader(strings.NewReader(line)) @@ -325,9 +325,8 @@ func TestStringRelatedRemittanceOptions(t *testing.T) { err := r.parseRelatedRemittance() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.RelatedRemittance.String() - require.Equal(t, str, "{8250} EDIC A ADDR ") - - str = r.currentFEDWireMessage.RelatedRemittance.String(true) - require.Equal(t, str, "{8250}*EDIC*A*ADDR*") + record := r.currentFEDWireMessage.RelatedRemittance + require.Equal(t, record.String(), "{8250} EDIC A ADDR ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8250}*EDIC*A*ADDR*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittance.go b/remittance.go index 6a16233f..1fa36335 100644 --- a/remittance.go +++ b/remittance.go @@ -99,19 +99,26 @@ func (ri *Remittance) UnmarshalJSON(data []byte) error { return nil } -// String writes Remittance -func (ri *Remittance) String(options ...bool) string { +// String returns a fixed-width Remittance record +func (ri *Remittance) String() string { + return ri.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a Remittance record formatted according to the FormatOptions +func (ri *Remittance) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(151) buf.WriteString(ri.tag) - buf.WriteString(ri.SwiftFieldTagField(options...)) - buf.WriteString(ri.SwiftLineOneField(options...)) - buf.WriteString(ri.SwiftLineTwoField(options...)) - buf.WriteString(ri.SwiftLineThreeField(options...)) - buf.WriteString(ri.SwiftLineFourField(options...)) + buf.WriteString(ri.FormatSwiftFieldTag(options)) + buf.WriteString(ri.FormatSwiftLineOne(options)) + buf.WriteString(ri.FormatSwiftLineTwo(options)) + buf.WriteString(ri.FormatSwiftLineThree(options)) + buf.WriteString(ri.FormatSwiftLineFour(options)) - if ri.parseFirstOption(options) { + if options.VariableLengthFields { return ri.stripDelimiters(buf.String()) } else { return buf.String() @@ -158,26 +165,51 @@ func (ri *Remittance) fieldInclusion() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (ri *Remittance) SwiftFieldTagField(options ...bool) string { - return ri.alphaVariableField(ri.CoverPayment.SwiftFieldTag, 5, ri.parseFirstOption(options)) +func (ri *Remittance) SwiftFieldTagField() string { + return ri.alphaField(ri.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (ri *Remittance) SwiftLineOneField(options ...bool) string { - return ri.alphaVariableField(ri.CoverPayment.SwiftLineOne, 35, ri.parseFirstOption(options)) +func (ri *Remittance) SwiftLineOneField() string { + return ri.alphaField(ri.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (ri *Remittance) SwiftLineTwoField(options ...bool) string { - return ri.alphaVariableField(ri.CoverPayment.SwiftLineTwo, 35, ri.parseFirstOption(options)) +func (ri *Remittance) SwiftLineTwoField() string { + return ri.alphaField(ri.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (ri *Remittance) SwiftLineThreeField(options ...bool) string { - return ri.alphaVariableField(ri.CoverPayment.SwiftLineThree, 35, ri.parseFirstOption(options)) +func (ri *Remittance) SwiftLineThreeField() string { + return ri.alphaField(ri.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (ri *Remittance) SwiftLineFourField(options ...bool) string { - return ri.alphaVariableField(ri.CoverPayment.SwiftLineFour, 35, ri.parseFirstOption(options)) +func (ri *Remittance) SwiftLineFourField() string { + return ri.alphaField(ri.CoverPayment.SwiftLineFour, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (ri *Remittance) FormatSwiftFieldTag(options FormatOptions) string { + return ri.formatAlphaField(ri.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (ri *Remittance) FormatSwiftLineOne(options FormatOptions) string { + return ri.formatAlphaField(ri.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (ri *Remittance) FormatSwiftLineTwo(options FormatOptions) string { + return ri.formatAlphaField(ri.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (ri *Remittance) FormatSwiftLineThree(options FormatOptions) string { + return ri.formatAlphaField(ri.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (ri *Remittance) FormatSwiftLineFour(options FormatOptions) string { + return ri.formatAlphaField(ri.CoverPayment.SwiftLineFour, 35, options) } diff --git a/remittanceBeneficiary.go b/remittanceBeneficiary.go index 2f0b75cd..037254af 100644 --- a/remittanceBeneficiary.go +++ b/remittanceBeneficiary.go @@ -233,37 +233,44 @@ func (rb *RemittanceBeneficiary) UnmarshalJSON(data []byte) error { return nil } -// String writes RemittanceBeneficiary -func (rb *RemittanceBeneficiary) String(options ...bool) string { +// String returns a fixed-width RemittanceBeneficiary record +func (rb *RemittanceBeneficiary) String() string { + return rb.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a RemittanceBeneficiary record formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(1114) buf.WriteString(rb.tag) - buf.WriteString(rb.NameField(options...)) - buf.WriteString(rb.IdentificationTypeField(options...)) - buf.WriteString(rb.IdentificationCodeField(options...)) - buf.WriteString(rb.IdentificationNumberField(options...)) - buf.WriteString(rb.IdentificationNumberIssuerField(options...)) - buf.WriteString(rb.DateBirthPlaceField(options...)) - buf.WriteString(rb.AddressTypeField(options...)) - buf.WriteString(rb.DepartmentField(options...)) - buf.WriteString(rb.SubDepartmentField(options...)) - buf.WriteString(rb.StreetNameField(options...)) - buf.WriteString(rb.BuildingNumberField(options...)) - buf.WriteString(rb.PostCodeField(options...)) - buf.WriteString(rb.TownNameField(options...)) - buf.WriteString(rb.CountrySubDivisionStateField(options...)) - buf.WriteString(rb.CountryField(options...)) - buf.WriteString(rb.AddressLineOneField(options...)) - buf.WriteString(rb.AddressLineTwoField(options...)) - buf.WriteString(rb.AddressLineThreeField(options...)) - buf.WriteString(rb.AddressLineFourField(options...)) - buf.WriteString(rb.AddressLineFiveField(options...)) - buf.WriteString(rb.AddressLineSixField(options...)) - buf.WriteString(rb.AddressLineSevenField(options...)) - buf.WriteString(rb.CountryOfResidenceField(options...)) - - if rb.parseFirstOption(options) { + buf.WriteString(rb.FormatName(options)) + buf.WriteString(rb.FormatIdentificationType(options)) + buf.WriteString(rb.FormatIdentificationCode(options)) + buf.WriteString(rb.FormatIdentificationNumber(options)) + buf.WriteString(rb.FormatIdentificationNumberIssuer(options)) + buf.WriteString(rb.FormatDateBirthPlace(options)) + buf.WriteString(rb.FormatAddressType(options)) + buf.WriteString(rb.FormatDepartment(options)) + buf.WriteString(rb.FormatSubDepartment(options)) + buf.WriteString(rb.FormatStreetName(options)) + buf.WriteString(rb.FormatBuildingNumber(options)) + buf.WriteString(rb.FormatPostCode(options)) + buf.WriteString(rb.FormatTownName(options)) + buf.WriteString(rb.FormatCountrySubDivisionState(options)) + buf.WriteString(rb.FormatCountry(options)) + buf.WriteString(rb.FormatAddressLineOne(options)) + buf.WriteString(rb.FormatAddressLineTwo(options)) + buf.WriteString(rb.FormatAddressLineThree(options)) + buf.WriteString(rb.FormatAddressLineFour(options)) + buf.WriteString(rb.FormatAddressLineFive(options)) + buf.WriteString(rb.FormatAddressLineSix(options)) + buf.WriteString(rb.FormatAddressLineSeven(options)) + buf.WriteString(rb.FormatCountryOfResidence(options)) + + if options.VariableLengthFields { return rb.stripDelimiters(buf.String()) } else { return buf.String() @@ -392,116 +399,231 @@ func (rb *RemittanceBeneficiary) fieldInclusion() error { } // NameField gets a string of the Name field -func (rb *RemittanceBeneficiary) NameField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.Name, 140, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) NameField() string { + return rb.alphaField(rb.RemittanceData.Name, 140) } // IdentificationTypeField gets a string of the IdentificationType field -func (rb *RemittanceBeneficiary) IdentificationTypeField(options ...bool) string { - return rb.alphaVariableField(rb.IdentificationType, 2, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) IdentificationTypeField() string { + return rb.alphaField(rb.IdentificationType, 2) } // IdentificationCodeField gets a string of the IdentificationCode field -func (rb *RemittanceBeneficiary) IdentificationCodeField(options ...bool) string { - return rb.alphaVariableField(rb.IdentificationCode, 4, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) IdentificationCodeField() string { + return rb.alphaField(rb.IdentificationCode, 4) } // IdentificationNumberField gets a string of the IdentificationNumber field -func (rb *RemittanceBeneficiary) IdentificationNumberField(options ...bool) string { - return rb.alphaVariableField(rb.IdentificationNumber, 35, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) IdentificationNumberField() string { + return rb.alphaField(rb.IdentificationNumber, 35) } // IdentificationNumberIssuerField gets a string of the IdentificationNumberIssuer field -func (rb *RemittanceBeneficiary) IdentificationNumberIssuerField(options ...bool) string { - return rb.alphaVariableField(rb.IdentificationNumberIssuer, 35, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) IdentificationNumberIssuerField() string { + return rb.alphaField(rb.IdentificationNumberIssuer, 35) } // DateBirthPlaceField gets a string of the DateBirthPlace field -func (rb *RemittanceBeneficiary) DateBirthPlaceField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.DateBirthPlace, 82, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) DateBirthPlaceField() string { + return rb.alphaField(rb.RemittanceData.DateBirthPlace, 82) } // AddressTypeField gets a string of the AddressType field -func (rb *RemittanceBeneficiary) AddressTypeField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressType, 4, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressTypeField() string { + return rb.alphaField(rb.RemittanceData.AddressType, 4) } // DepartmentField gets a string of the Department field -func (rb *RemittanceBeneficiary) DepartmentField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.Department, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) DepartmentField() string { + return rb.alphaField(rb.RemittanceData.Department, 70) } // SubDepartmentField gets a string of the SubDepartment field -func (rb *RemittanceBeneficiary) SubDepartmentField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.SubDepartment, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) SubDepartmentField() string { + return rb.alphaField(rb.RemittanceData.SubDepartment, 70) } // StreetNameField gets a string of the StreetName field -func (rb *RemittanceBeneficiary) StreetNameField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.StreetName, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) StreetNameField() string { + return rb.alphaField(rb.RemittanceData.StreetName, 70) } // BuildingNumberField gets a string of the BuildingNumber field -func (rb *RemittanceBeneficiary) BuildingNumberField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.BuildingNumber, 16, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) BuildingNumberField() string { + return rb.alphaField(rb.RemittanceData.BuildingNumber, 16) } // PostCodeField gets a string of the PostCode field -func (rb *RemittanceBeneficiary) PostCodeField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.PostCode, 16, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) PostCodeField() string { + return rb.alphaField(rb.RemittanceData.PostCode, 16) } // TownNameField gets a string of the TownName field -func (rb *RemittanceBeneficiary) TownNameField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.TownName, 35, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) TownNameField() string { + return rb.alphaField(rb.RemittanceData.TownName, 35) } // CountrySubDivisionStateField gets a string of the CountrySubDivisionState field -func (rb *RemittanceBeneficiary) CountrySubDivisionStateField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.CountrySubDivisionState, 35, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) CountrySubDivisionStateField() string { + return rb.alphaField(rb.RemittanceData.CountrySubDivisionState, 35) } // CountryField gets a string of the Country field -func (rb *RemittanceBeneficiary) CountryField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.Country, 2, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) CountryField() string { + return rb.alphaField(rb.RemittanceData.Country, 2) } // AddressLineOneField gets a string of the AddressLineOne field -func (rb *RemittanceBeneficiary) AddressLineOneField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineOne, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineOneField() string { + return rb.alphaField(rb.RemittanceData.AddressLineOne, 70) } // AddressLineTwoField gets a string of the AddressLineTwo field -func (rb *RemittanceBeneficiary) AddressLineTwoField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineTwo, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineTwoField() string { + return rb.alphaField(rb.RemittanceData.AddressLineTwo, 70) } // AddressLineThreeField gets a string of the AddressLineThree field -func (rb *RemittanceBeneficiary) AddressLineThreeField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineThree, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineThreeField() string { + return rb.alphaField(rb.RemittanceData.AddressLineThree, 70) } // AddressLineFourField gets a string of the AddressLineFour field -func (rb *RemittanceBeneficiary) AddressLineFourField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineFour, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineFourField() string { + return rb.alphaField(rb.RemittanceData.AddressLineFour, 70) } // AddressLineFiveField gets a string of the AddressLineFive field -func (rb *RemittanceBeneficiary) AddressLineFiveField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineFive, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineFiveField() string { + return rb.alphaField(rb.RemittanceData.AddressLineFive, 70) } // AddressLineSixField gets a string of the AddressLineSix field -func (rb *RemittanceBeneficiary) AddressLineSixField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineSix, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineSixField() string { + return rb.alphaField(rb.RemittanceData.AddressLineSix, 70) } // AddressLineSevenField gets a string of the AddressLineSeven field -func (rb *RemittanceBeneficiary) AddressLineSevenField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.AddressLineSeven, 70, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) AddressLineSevenField() string { + return rb.alphaField(rb.RemittanceData.AddressLineSeven, 70) } // CountryOfResidenceField gets a string of the CountryOfResidence field -func (rb *RemittanceBeneficiary) CountryOfResidenceField(options ...bool) string { - return rb.alphaVariableField(rb.RemittanceData.CountryOfResidence, 2, rb.parseFirstOption(options)) +func (rb *RemittanceBeneficiary) CountryOfResidenceField() string { + return rb.alphaField(rb.RemittanceData.CountryOfResidence, 2) +} + +// FormatName returns Name formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatName(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.Name, 140, options) +} + +// FormatIdentificationType returns IdentificationType formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatIdentificationType(options FormatOptions) string { + return rb.formatAlphaField(rb.IdentificationType, 2, options) +} + +// FormatIdentificationCode returns IdentificationCode formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatIdentificationCode(options FormatOptions) string { + return rb.formatAlphaField(rb.IdentificationCode, 4, options) +} + +// FormatIdentificationNumber returns IdentificationNumber formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatIdentificationNumber(options FormatOptions) string { + return rb.formatAlphaField(rb.IdentificationNumber, 35, options) +} + +// FormatIdentificationNumberIssuer returns IdentificationNumberIssuer formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatIdentificationNumberIssuer(options FormatOptions) string { + return rb.formatAlphaField(rb.IdentificationNumberIssuer, 35, options) +} + +// FormatDateBirthPlace returns DateBirthPlace formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatDateBirthPlace(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.DateBirthPlace, 82, options) +} + +// FormatAddressType returns AddressType formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressType(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressType, 4, options) +} + +// FormatDepartment returns Department formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatDepartment(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.Department, 70, options) +} + +// FormatSubDepartment returns SubDepartment formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatSubDepartment(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.SubDepartment, 70, options) +} + +// FormatStreetName returns StreetName formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatStreetName(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.StreetName, 70, options) +} + +// FormatBuildingNumber returns BuildingNumber formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatBuildingNumber(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.BuildingNumber, 16, options) +} + +// FormatPostCode returns PostCode formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatPostCode(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.PostCode, 16, options) +} + +// FormatTownName returns TownName formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatTownName(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.TownName, 35, options) +} + +// FormatCountrySubDivisionState returns CountrySubDivisionState formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatCountrySubDivisionState(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.CountrySubDivisionState, 35, options) +} + +// FormatCountry returns Country formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatCountry(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.Country, 2, options) +} + +// FormatAddressLineOne returns AddressLineOne formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineOne(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineOne, 70, options) +} + +// FormatAddressLineTwo returns AddressLineTwo formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineTwo(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineTwo, 70, options) +} + +// FormatAddressLineThree returns AddressLineThree formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineThree(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineThree, 70, options) +} + +// FormatAddressLineFour returns AddressLineFour formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineFour(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineFour, 70, options) +} + +// FormatAddressLineFive returns AddressLineFive formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineFive(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineFive, 70, options) +} + +// FormatAddressLineSix returns AddressLineSix formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineSix(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineSix, 70, options) +} + +// FormatAddressLineSeven returns AddressLineSeven formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatAddressLineSeven(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.AddressLineSeven, 70, options) +} + +// FormatCountryOfResidence returns CountryOfResidence formatted according to the FormatOptions +func (rb *RemittanceBeneficiary) FormatCountryOfResidence(options FormatOptions) string { + return rb.formatAlphaField(rb.RemittanceData.CountryOfResidence, 2, options) } diff --git a/remittanceBeneficiary_test.go b/remittanceBeneficiary_test.go index 62dc8171..8262fe71 100644 --- a/remittanceBeneficiary_test.go +++ b/remittanceBeneficiary_test.go @@ -405,7 +405,7 @@ func TestStringRemittanceBeneficiaryVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringRemittanceBeneficiaryOptions validates string() with options +// TestStringRemittanceBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceBeneficiaryOptions(t *testing.T) { var line = "{8350}Name*PIARNU***ADDR" r := NewReader(strings.NewReader(line)) @@ -414,9 +414,8 @@ func TestStringRemittanceBeneficiaryOptions(t *testing.T) { err := r.parseRemittanceBeneficiary() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.RemittanceBeneficiary.String() - require.Equal(t, str, "{8350}Name PIARNU ADDR ") - - str = r.currentFEDWireMessage.RemittanceBeneficiary.String(true) - require.Equal(t, str, "{8350}Name*PIARNU***ADDR*") + record := r.currentFEDWireMessage.RemittanceBeneficiary + require.Equal(t, record.String(), "{8350}Name PIARNU ADDR ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8350}Name*PIARNU***ADDR*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittanceFreeText.go b/remittanceFreeText.go index 6310d8fb..c6c6ed43 100644 --- a/remittanceFreeText.go +++ b/remittanceFreeText.go @@ -89,17 +89,24 @@ func (rft *RemittanceFreeText) UnmarshalJSON(data []byte) error { return nil } -// String writes RemittanceFreeText -func (rft *RemittanceFreeText) String(options ...bool) string { +// String returns a fixed-width RemittanceFreeText record +func (rft *RemittanceFreeText) String() string { + return rft.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a RemittanceFreeText record formatted according to the FormatOptions +func (rft *RemittanceFreeText) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(426) buf.WriteString(rft.tag) - buf.WriteString(rft.LineOneField(options...)) - buf.WriteString(rft.LineTwoField(options...)) - buf.WriteString(rft.LineThreeField(options...)) + buf.WriteString(rft.FormatLineOne(options)) + buf.WriteString(rft.FormatLineTwo(options)) + buf.WriteString(rft.FormatLineThree(options)) - if rft.parseFirstOption(options) { + if options.VariableLengthFields { return rft.stripDelimiters(buf.String()) } else { return buf.String() @@ -125,16 +132,31 @@ func (rft *RemittanceFreeText) Validate() error { } // LineOneField gets a string of the LineOne field -func (rft *RemittanceFreeText) LineOneField(options ...bool) string { - return rft.alphaVariableField(rft.LineOne, 140, rft.parseFirstOption(options)) +func (rft *RemittanceFreeText) LineOneField() string { + return rft.alphaField(rft.LineOne, 140) } // LineTwoField gets a string of the LineTwo field -func (rft *RemittanceFreeText) LineTwoField(options ...bool) string { - return rft.alphaVariableField(rft.LineTwo, 140, rft.parseFirstOption(options)) +func (rft *RemittanceFreeText) LineTwoField() string { + return rft.alphaField(rft.LineTwo, 140) } // LineThreeField gets a string of the LineThree field -func (rft *RemittanceFreeText) LineThreeField(options ...bool) string { - return rft.alphaVariableField(rft.LineThree, 140, rft.parseFirstOption(options)) +func (rft *RemittanceFreeText) LineThreeField() string { + return rft.alphaField(rft.LineThree, 140) +} + +// FormatLineOne returns LineOne formatted according to the FormatOptions +func (rft *RemittanceFreeText) FormatLineOne(options FormatOptions) string { + return rft.formatAlphaField(rft.LineOne, 140, options) +} + +// FormatLineTwo returns LineTwo formatted according to the FormatOptions +func (rft *RemittanceFreeText) FormatLineTwo(options FormatOptions) string { + return rft.formatAlphaField(rft.LineTwo, 140, options) +} + +// FormatLineThree returns LineThree formatted according to the FormatOptions +func (rft *RemittanceFreeText) FormatLineThree(options FormatOptions) string { + return rft.formatAlphaField(rft.LineThree, 140, options) } diff --git a/remittanceFreeText_test.go b/remittanceFreeText_test.go index ba840ac7..6ba9262e 100644 --- a/remittanceFreeText_test.go +++ b/remittanceFreeText_test.go @@ -118,7 +118,7 @@ func TestStringRemittanceFreeTextVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringRemittanceFreeTextOptions validates string() with options +// TestStringRemittanceFreeTextOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceFreeTextOptions(t *testing.T) { var line = "{8750}" r := NewReader(strings.NewReader(line)) @@ -127,9 +127,8 @@ func TestStringRemittanceFreeTextOptions(t *testing.T) { err := r.parseRemittanceFreeText() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.RemittanceFreeText.String() - require.Equal(t, str, "{8750} ") - - str = r.currentFEDWireMessage.RemittanceFreeText.String(true) - require.Equal(t, str, "{8750}*") + record := r.currentFEDWireMessage.RemittanceFreeText + require.Equal(t, record.String(), "{8750} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8750}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittanceOriginator.go b/remittanceOriginator.go index 9f521d81..dc69a2e9 100644 --- a/remittanceOriginator.go +++ b/remittanceOriginator.go @@ -287,43 +287,50 @@ func (ro *RemittanceOriginator) UnmarshalJSON(data []byte) error { return nil } -// String writes RemittanceOriginator -func (ro *RemittanceOriginator) String(options ...bool) string { +// String returns a fixed-width RemittanceOriginator record +func (ro *RemittanceOriginator) String() string { + return ro.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a RemittanceOriginator record formatted according to the FormatOptions +func (ro *RemittanceOriginator) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(3442) buf.WriteString(ro.tag) - buf.WriteString(ro.IdentificationTypeField(options...)) - buf.WriteString(ro.IdentificationCodeField(options...)) - buf.WriteString(ro.NameField(options...)) - buf.WriteString(ro.IdentificationNumberField(options...)) - buf.WriteString(ro.IdentificationNumberIssuerField(options...)) - buf.WriteString(ro.DateBirthPlaceField(options...)) - buf.WriteString(ro.AddressTypeField(options...)) - buf.WriteString(ro.DepartmentField(options...)) - buf.WriteString(ro.SubDepartmentField(options...)) - buf.WriteString(ro.StreetNameField(options...)) - buf.WriteString(ro.BuildingNumberField(options...)) - buf.WriteString(ro.PostCodeField(options...)) - buf.WriteString(ro.TownNameField(options...)) - buf.WriteString(ro.CountrySubDivisionStateField(options...)) - buf.WriteString(ro.CountryField(options...)) - buf.WriteString(ro.AddressLineOneField(options...)) - buf.WriteString(ro.AddressLineTwoField(options...)) - buf.WriteString(ro.AddressLineThreeField(options...)) - buf.WriteString(ro.AddressLineFourField(options...)) - buf.WriteString(ro.AddressLineFiveField(options...)) - buf.WriteString(ro.AddressLineSixField(options...)) - buf.WriteString(ro.AddressLineSevenField(options...)) - buf.WriteString(ro.CountryOfResidenceField(options...)) - buf.WriteString(ro.ContactNameField(options...)) - buf.WriteString(ro.ContactPhoneNumberField(options...)) - buf.WriteString(ro.ContactMobileNumberField(options...)) - buf.WriteString(ro.ContactFaxNumberField(options...)) - buf.WriteString(ro.ContactElectronicAddressField(options...)) - buf.WriteString(ro.ContactOtherField(options...)) - - if ro.parseFirstOption(options) { + buf.WriteString(ro.FormatIdentificationType(options)) + buf.WriteString(ro.FormatIdentificationCode(options)) + buf.WriteString(ro.FormatName(options)) + buf.WriteString(ro.FormatIdentificationNumber(options)) + buf.WriteString(ro.FormatIdentificationNumberIssuer(options)) + buf.WriteString(ro.FormatDateBirthPlace(options)) + buf.WriteString(ro.FormatAddressType(options)) + buf.WriteString(ro.FormatDepartment(options)) + buf.WriteString(ro.FormatSubDepartment(options)) + buf.WriteString(ro.FormatStreetName(options)) + buf.WriteString(ro.FormatBuildingNumber(options)) + buf.WriteString(ro.FormatPostCode(options)) + buf.WriteString(ro.FormatTownName(options)) + buf.WriteString(ro.FormatCountrySubDivisionState(options)) + buf.WriteString(ro.FormatCountry(options)) + buf.WriteString(ro.FormatAddressLineOne(options)) + buf.WriteString(ro.FormatAddressLineTwo(options)) + buf.WriteString(ro.FormatAddressLineThree(options)) + buf.WriteString(ro.FormatAddressLineFour(options)) + buf.WriteString(ro.FormatAddressLineFive(options)) + buf.WriteString(ro.FormatAddressLineSix(options)) + buf.WriteString(ro.FormatAddressLineSeven(options)) + buf.WriteString(ro.FormatCountryOfResidence(options)) + buf.WriteString(ro.FormatContactName(options)) + buf.WriteString(ro.FormatContactPhoneNumber(options)) + buf.WriteString(ro.FormatContactMobileNumber(options)) + buf.WriteString(ro.FormatContactFaxNumber(options)) + buf.WriteString(ro.FormatContactElectronicAddress(options)) + buf.WriteString(ro.FormatContactOther(options)) + + if options.VariableLengthFields { return ro.stripDelimiters(buf.String()) } else { return buf.String() @@ -469,146 +476,291 @@ func (ro *RemittanceOriginator) fieldInclusion() error { } // IdentificationTypeField gets a string of the IdentificationType field -func (ro *RemittanceOriginator) IdentificationTypeField(options ...bool) string { - return ro.alphaVariableField(ro.IdentificationType, 2, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) IdentificationTypeField() string { + return ro.alphaField(ro.IdentificationType, 2) } // IdentificationCodeField gets a string of the IdentificationCode field -func (ro *RemittanceOriginator) IdentificationCodeField(options ...bool) string { - return ro.alphaVariableField(ro.IdentificationCode, 4, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) IdentificationCodeField() string { + return ro.alphaField(ro.IdentificationCode, 4) } // NameField gets a string of the Name field -func (ro *RemittanceOriginator) NameField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.Name, 140, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) NameField() string { + return ro.alphaField(ro.RemittanceData.Name, 140) } // IdentificationNumberField gets a string of the IdentificationNumber field -func (ro *RemittanceOriginator) IdentificationNumberField(options ...bool) string { - return ro.alphaVariableField(ro.IdentificationNumber, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) IdentificationNumberField() string { + return ro.alphaField(ro.IdentificationNumber, 35) } // IdentificationNumberIssuerField gets a string of the IdentificationNumberIssuer field -func (ro *RemittanceOriginator) IdentificationNumberIssuerField(options ...bool) string { - return ro.alphaVariableField(ro.IdentificationNumberIssuer, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) IdentificationNumberIssuerField() string { + return ro.alphaField(ro.IdentificationNumberIssuer, 35) } // DateBirthPlaceField gets a string of the DateBirthPlace field -func (ro *RemittanceOriginator) DateBirthPlaceField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.DateBirthPlace, 82, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) DateBirthPlaceField() string { + return ro.alphaField(ro.RemittanceData.DateBirthPlace, 82) } // AddressTypeField gets a string of the AddressType field -func (ro *RemittanceOriginator) AddressTypeField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressType, 4, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressTypeField() string { + return ro.alphaField(ro.RemittanceData.AddressType, 4) } // DepartmentField gets a string of the Department field -func (ro *RemittanceOriginator) DepartmentField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.Department, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) DepartmentField() string { + return ro.alphaField(ro.RemittanceData.Department, 70) } // SubDepartmentField gets a string of the SubDepartment field -func (ro *RemittanceOriginator) SubDepartmentField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.SubDepartment, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) SubDepartmentField() string { + return ro.alphaField(ro.RemittanceData.SubDepartment, 70) } // StreetNameField gets a string of the StreetName field -func (ro *RemittanceOriginator) StreetNameField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.StreetName, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) StreetNameField() string { + return ro.alphaField(ro.RemittanceData.StreetName, 70) } // BuildingNumberField gets a string of the BuildingNumber field -func (ro *RemittanceOriginator) BuildingNumberField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.BuildingNumber, 16, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) BuildingNumberField() string { + return ro.alphaField(ro.RemittanceData.BuildingNumber, 16) } // PostCodeField gets a string of the PostCode field -func (ro *RemittanceOriginator) PostCodeField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.PostCode, 16, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) PostCodeField() string { + return ro.alphaField(ro.RemittanceData.PostCode, 16) } // TownNameField gets a string of the TownName field -func (ro *RemittanceOriginator) TownNameField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.TownName, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) TownNameField() string { + return ro.alphaField(ro.RemittanceData.TownName, 35) } // CountrySubDivisionStateField gets a string of the CountrySubDivisionState field -func (ro *RemittanceOriginator) CountrySubDivisionStateField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.CountrySubDivisionState, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) CountrySubDivisionStateField() string { + return ro.alphaField(ro.RemittanceData.CountrySubDivisionState, 35) } // CountryField gets a string of the Country field -func (ro *RemittanceOriginator) CountryField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.Country, 2, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) CountryField() string { + return ro.alphaField(ro.RemittanceData.Country, 2) } // AddressLineOneField gets a string of the AddressLineOne field -func (ro *RemittanceOriginator) AddressLineOneField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineOne, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineOneField() string { + return ro.alphaField(ro.RemittanceData.AddressLineOne, 70) } // AddressLineTwoField gets a string of the AddressLineTwo field -func (ro *RemittanceOriginator) AddressLineTwoField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineTwo, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineTwoField() string { + return ro.alphaField(ro.RemittanceData.AddressLineTwo, 70) } // AddressLineThreeField gets a string of the AddressLineThree field -func (ro *RemittanceOriginator) AddressLineThreeField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineThree, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineThreeField() string { + return ro.alphaField(ro.RemittanceData.AddressLineThree, 70) } // AddressLineFourField gets a string of the AddressLineFour field -func (ro *RemittanceOriginator) AddressLineFourField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineOne, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineFourField() string { + return ro.alphaField(ro.RemittanceData.AddressLineFour, 70) } // AddressLineFiveField gets a string of the AddressLineFive field -func (ro *RemittanceOriginator) AddressLineFiveField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineFive, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineFiveField() string { + return ro.alphaField(ro.RemittanceData.AddressLineFive, 70) } // AddressLineSixField gets a string of the AddressLineSix field -func (ro *RemittanceOriginator) AddressLineSixField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineSix, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineSixField() string { + return ro.alphaField(ro.RemittanceData.AddressLineSix, 70) } // AddressLineSevenField gets a string of the AddressLineSeven field -func (ro *RemittanceOriginator) AddressLineSevenField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.AddressLineSeven, 70, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) AddressLineSevenField() string { + return ro.alphaField(ro.RemittanceData.AddressLineSeven, 70) } // CountryOfResidenceField gets a string of the CountryOfResidence field -func (ro *RemittanceOriginator) CountryOfResidenceField(options ...bool) string { - return ro.alphaVariableField(ro.RemittanceData.CountryOfResidence, 2, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) CountryOfResidenceField() string { + return ro.alphaField(ro.RemittanceData.CountryOfResidence, 2) } // ContactNameField gets a string of the ContactName field -func (ro *RemittanceOriginator) ContactNameField(options ...bool) string { - return ro.alphaVariableField(ro.ContactName, 140, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactNameField() string { + return ro.alphaField(ro.ContactName, 140) } // ContactPhoneNumberField gets a string of the ContactPhoneNumber field -func (ro *RemittanceOriginator) ContactPhoneNumberField(options ...bool) string { - return ro.alphaVariableField(ro.ContactPhoneNumber, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactPhoneNumberField() string { + return ro.alphaField(ro.ContactPhoneNumber, 35) } // ContactMobileNumberField gets a string of the ContactMobileNumber field -func (ro *RemittanceOriginator) ContactMobileNumberField(options ...bool) string { - return ro.alphaVariableField(ro.ContactMobileNumber, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactMobileNumberField() string { + return ro.alphaField(ro.ContactMobileNumber, 35) } // ContactFaxNumberField gets a string of the ContactFaxNumber field -func (ro *RemittanceOriginator) ContactFaxNumberField(options ...bool) string { - return ro.alphaVariableField(ro.ContactFaxNumber, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactFaxNumberField() string { + return ro.alphaField(ro.ContactFaxNumber, 35) } // ContactElectronicAddressField gets a string of the ContactElectronicAddress field -func (ro *RemittanceOriginator) ContactElectronicAddressField(options ...bool) string { - return ro.alphaVariableField(ro.ContactElectronicAddress, 2048, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactElectronicAddressField() string { + return ro.alphaField(ro.ContactElectronicAddress, 2048) } // ContactOtherField gets a string of the ContactOther field -func (ro *RemittanceOriginator) ContactOtherField(options ...bool) string { - return ro.alphaVariableField(ro.ContactOther, 35, ro.parseFirstOption(options)) +func (ro *RemittanceOriginator) ContactOtherField() string { + return ro.alphaField(ro.ContactOther, 35) +} + +// FormatIdentificationType returns IdentificationType formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatIdentificationType(options FormatOptions) string { + return ro.formatAlphaField(ro.IdentificationType, 2, options) +} + +// FormatIdentificationCode returns IdentificationCode formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatIdentificationCode(options FormatOptions) string { + return ro.formatAlphaField(ro.IdentificationCode, 4, options) +} + +// FormatName returns Name formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatName(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.Name, 140, options) +} + +// FormatIdentificationNumber returns IdentificationNumber formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatIdentificationNumber(options FormatOptions) string { + return ro.formatAlphaField(ro.IdentificationNumber, 35, options) +} + +// FormatIdentificationNumberIssuer returns IdentificationNumberIssuer formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatIdentificationNumberIssuer(options FormatOptions) string { + return ro.formatAlphaField(ro.IdentificationNumberIssuer, 35, options) +} + +// FormatDateBirthPlace returns DateBirthPlace formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatDateBirthPlace(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.DateBirthPlace, 82, options) +} + +// FormatAddressType returns AddressType formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressType(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressType, 4, options) +} + +// FormatDepartment returns Department formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatDepartment(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.Department, 70, options) +} + +// FormatSubDepartment returns SubDepartment formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatSubDepartment(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.SubDepartment, 70, options) +} + +// FormatStreetName returns StreetName formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatStreetName(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.StreetName, 70, options) +} + +// FormatBuildingNumber returns BuildingNumber formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatBuildingNumber(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.BuildingNumber, 16, options) +} + +// FormatPostCode returns PostCode formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatPostCode(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.PostCode, 16, options) +} + +// FormatTownName returns TownName formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatTownName(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.TownName, 35, options) +} + +// FormatCountrySubDivisionState returns CountrySubDivisionState formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatCountrySubDivisionState(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.CountrySubDivisionState, 35, options) +} + +// FormatCountry returns Country formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatCountry(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.Country, 2, options) +} + +// FormatAddressLineOne returns AddressLineOne formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineOne(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineOne, 70, options) +} + +// FormatAddressLineTwo returns AddressLineTwo formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineTwo(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineTwo, 70, options) +} + +// FormatAddressLineThree returns AddressLineThree formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineThree(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineThree, 70, options) +} + +// FormatAddressLineFour returns AddressLineFour formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineFour(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineOne, 70, options) +} + +// FormatAddressLineFive returns AddressLineFive formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineFive(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineFive, 70, options) +} + +// FormatAddressLineSix returns AddressLineSix formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineSix(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineSix, 70, options) +} + +// FormatAddressLineSeven returns AddressLineSeven formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatAddressLineSeven(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.AddressLineSeven, 70, options) +} + +// FormatCountryOfResidence returns CountryOfResidence formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatCountryOfResidence(options FormatOptions) string { + return ro.formatAlphaField(ro.RemittanceData.CountryOfResidence, 2, options) +} + +// FormatContactName returns ContactName formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactName(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactName, 140, options) +} + +// FormatContactPhoneNumber returns ContactPhoneNumber formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactPhoneNumber(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactPhoneNumber, 35, options) +} + +// FormatContactMobileNumber returns ContactMobileNumber formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactMobileNumber(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactMobileNumber, 35, options) +} + +// FormatContactFaxNumber returns ContactFaxNumber formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactFaxNumber(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactFaxNumber, 35, options) +} + +// FormatContactElectronicAddress returns ContactElectronicAddress formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactElectronicAddress(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactElectronicAddress, 2048, options) +} + +// FormatContactOther returns ContactOther formatted according to the FormatOptions +func (ro *RemittanceOriginator) FormatContactOther(options FormatOptions) string { + return ro.formatAlphaField(ro.ContactOther, 35, options) } diff --git a/remittanceOriginator_test.go b/remittanceOriginator_test.go index 4812fafb..12b927d2 100644 --- a/remittanceOriginator_test.go +++ b/remittanceOriginator_test.go @@ -14,7 +14,7 @@ func mockRemittanceOriginator() *RemittanceOriginator { ro.IdentificationCode = OICCustomerNumber ro.IdentificationNumber = "111111" ro.IdentificationNumberIssuer = "Bank" - //ro.RemittanceData.DateBirthPlace = "12072008 AnyTown" + // ro.RemittanceData.DateBirthPlace = "12072008 AnyTown" ro.RemittanceData.Name = "Name" ro.RemittanceData.AddressType = CompletePostalAddress ro.RemittanceData.Department = "Department" @@ -473,7 +473,7 @@ func TestStringRemittanceOriginatorVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringRemittanceOriginatorOptions validates string() with options +// TestStringRemittanceOriginatorOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceOriginatorOptions(t *testing.T) { var line = "{8300}OICUSTName****ADDR" r := NewReader(strings.NewReader(line)) @@ -482,9 +482,8 @@ func TestStringRemittanceOriginatorOptions(t *testing.T) { err := r.parseRemittanceOriginator() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.RemittanceOriginator.String() - require.Equal(t, str, "{8300}OICUSTName ADDR ") - - str = r.currentFEDWireMessage.RemittanceOriginator.String(true) - require.Equal(t, str, "{8300}OICUSTName****ADDR*") + record := r.currentFEDWireMessage.RemittanceOriginator + require.Equal(t, record.String(), "{8300}OICUSTName ADDR ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8300}OICUSTName****ADDR*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittance_test.go b/remittance_test.go index f36ce257..7ad72f49 100644 --- a/remittance_test.go +++ b/remittance_test.go @@ -160,7 +160,7 @@ func TestStringRemittanceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringRemittanceOptions validates string() with options +// TestStringRemittanceOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceOptions(t *testing.T) { var line = "{7070}*" r := NewReader(strings.NewReader(line)) @@ -169,9 +169,8 @@ func TestStringRemittanceOptions(t *testing.T) { err := r.parseRemittance() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.Remittance.String() - require.Equal(t, str, "{7070} ") - - str = r.currentFEDWireMessage.Remittance.String(true) - require.Equal(t, str, "{7070}*") + record := r.currentFEDWireMessage.Remittance + require.Equal(t, record.String(), "{7070} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7070}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/secondaryRemittanceDocument.go b/secondaryRemittanceDocument.go index a8c73012..dc433bdc 100644 --- a/secondaryRemittanceDocument.go +++ b/secondaryRemittanceDocument.go @@ -98,18 +98,25 @@ func (srd *SecondaryRemittanceDocument) UnmarshalJSON(data []byte) error { return nil } -// String writes SecondaryRemittanceDocument -func (srd *SecondaryRemittanceDocument) String(options ...bool) string { +// String returns a fixed-width SecondaryRemittanceDocument record +func (srd *SecondaryRemittanceDocument) String() string { + return srd.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a SecondaryRemittanceDocument record formatted according to the FormatOptions +func (srd *SecondaryRemittanceDocument) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(115) buf.WriteString(srd.tag) - buf.WriteString(srd.DocumentTypeCodeField(options...)) - buf.WriteString(srd.ProprietaryDocumentTypeCodeField(options...)) - buf.WriteString(srd.DocumentIdentificationNumberField(options...)) - buf.WriteString(srd.IssuerField(options...)) + buf.WriteString(srd.FormatDocumentTypeCode(options)) + buf.WriteString(srd.FormatProprietaryDocumentTypeCode(options)) + buf.WriteString(srd.FormatDocumentIdentificationNumber(options)) + buf.WriteString(srd.FormatIssuer(options)) - if srd.parseFirstOption(options) { + if options.VariableLengthFields { return srd.stripDelimiters(buf.String()) } else { return buf.String() @@ -161,22 +168,22 @@ func (srd *SecondaryRemittanceDocument) fieldInclusion() error { return nil } -// DocumentTypeCodeField gets a string of the DocumentTypeCode field -func (srd *SecondaryRemittanceDocument) DocumentTypeCodeField(options ...bool) string { - return srd.alphaVariableField(srd.DocumentTypeCode, 4, srd.parseFirstOption(options)) +// FormatDocumentTypeCode returns DocumentTypeCode formatted according to the FormatOptions +func (srd *SecondaryRemittanceDocument) FormatDocumentTypeCode(options FormatOptions) string { + return srd.formatAlphaField(srd.DocumentTypeCode, 4, options) } -// ProprietaryDocumentTypeCodeField gets a string of the ProprietaryDocumentTypeCode field -func (srd *SecondaryRemittanceDocument) ProprietaryDocumentTypeCodeField(options ...bool) string { - return srd.alphaVariableField(srd.ProprietaryDocumentTypeCode, 35, srd.parseFirstOption(options)) +// FormatProprietaryDocumentTypeCode returns ProprietaryDocumentTypeCode formatted according to the FormatOptions +func (srd *SecondaryRemittanceDocument) FormatProprietaryDocumentTypeCode(options FormatOptions) string { + return srd.formatAlphaField(srd.ProprietaryDocumentTypeCode, 35, options) } -// DocumentIdentificationNumberField gets a string of the DocumentIdentificationNumber field -func (srd *SecondaryRemittanceDocument) DocumentIdentificationNumberField(options ...bool) string { - return srd.alphaVariableField(srd.DocumentIdentificationNumber, 35, srd.parseFirstOption(options)) +// FormatDocumentIdentificationNumber returns DocumentIdentificationNumber formatted according to the FormatOptions +func (srd *SecondaryRemittanceDocument) FormatDocumentIdentificationNumber(options FormatOptions) string { + return srd.formatAlphaField(srd.DocumentIdentificationNumber, 35, options) } -// IssuerField gets a string of the Issuer field -func (srd *SecondaryRemittanceDocument) IssuerField(options ...bool) string { - return srd.alphaVariableField(srd.Issuer, 35, srd.parseFirstOption(options)) +// FormatIssuer returns Issuer formatted according to the FormatOptions +func (srd *SecondaryRemittanceDocument) FormatIssuer(options FormatOptions) string { + return srd.formatAlphaField(srd.Issuer, 35, options) } diff --git a/secondaryRemittanceDocument_test.go b/secondaryRemittanceDocument_test.go index 1d5be7a3..3dbaa0c9 100644 --- a/secondaryRemittanceDocument_test.go +++ b/secondaryRemittanceDocument_test.go @@ -162,7 +162,7 @@ func TestStringSecondaryRemittanceDocumentVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringSecondaryRemittanceDocumentOptions validates string() with options +// TestStringSecondaryRemittanceDocumentOptions validates Format() formatted according to the FormatOptions func TestStringSecondaryRemittanceDocumentOptions(t *testing.T) { var line = "{8700}AROI*A*" r := NewReader(strings.NewReader(line)) @@ -171,9 +171,8 @@ func TestStringSecondaryRemittanceDocumentOptions(t *testing.T) { err := r.parseSecondaryRemittanceDocument() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.SecondaryRemittanceDocument.String() - require.Equal(t, str, "{8700}AROI A ") - - str = r.currentFEDWireMessage.SecondaryRemittanceDocument.String(true) - require.Equal(t, str, "{8700}AROI*A*") + record := r.currentFEDWireMessage.SecondaryRemittanceDocument + require.Equal(t, record.String(), "{8700}AROI A ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8700}AROI*A*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderDepositoryInstitution.go b/senderDepositoryInstitution.go index 5a0b87ca..8fbafbc4 100644 --- a/senderDepositoryInstitution.go +++ b/senderDepositoryInstitution.go @@ -80,14 +80,21 @@ func (sdi *SenderDepositoryInstitution) UnmarshalJSON(data []byte) error { return nil } -// String writes SenderDepositoryInstitution -func (sdi *SenderDepositoryInstitution) String(options ...bool) string { +// String returns a fixed-width SenderDepositoryInstitution record +func (sdi *SenderDepositoryInstitution) String() string { + return sdi.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a SenderDepositoryInstitution record formatted according to the FormatOptions +func (sdi *SenderDepositoryInstitution) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(39) buf.WriteString(sdi.tag) - buf.WriteString(sdi.SenderABANumberField(options...)) - buf.WriteString(sdi.SenderShortNameField(options...)) + buf.WriteString(sdi.FormatSenderABANumber(options)) + buf.WriteString(sdi.FormatSenderShortName(options)) return buf.String() } @@ -123,11 +130,21 @@ func (sdi *SenderDepositoryInstitution) fieldInclusion() error { } // SenderABANumberField gets a string of the SenderABANumber field -func (sdi *SenderDepositoryInstitution) SenderABANumberField(options ...bool) string { - return sdi.alphaVariableField(sdi.SenderABANumber, 9, sdi.parseFirstOption(options)) +func (sdi *SenderDepositoryInstitution) SenderABANumberField() string { + return sdi.alphaField(sdi.SenderABANumber, 9) } // SenderShortNameField gets a string of the SenderShortName field -func (sdi *SenderDepositoryInstitution) SenderShortNameField(options ...bool) string { - return sdi.alphaVariableField(sdi.SenderShortName, 18, sdi.parseFirstOption(options)) +func (sdi *SenderDepositoryInstitution) SenderShortNameField() string { + return sdi.alphaField(sdi.SenderShortName, 18) +} + +// FormatSenderABANumber returns SenderABANumber formatted according to the FormatOptions +func (sdi *SenderDepositoryInstitution) FormatSenderABANumber(options FormatOptions) string { + return sdi.formatAlphaField(sdi.SenderABANumber, 9, options) +} + +// FormatSenderShortName returns SenderShortName formatted according to the FormatOptions +func (sdi *SenderDepositoryInstitution) FormatSenderShortName(options FormatOptions) string { + return sdi.formatAlphaField(sdi.SenderShortName, 18, options) } diff --git a/senderDepositoryInstitution_test.go b/senderDepositoryInstitution_test.go index c83547f3..37edc548 100644 --- a/senderDepositoryInstitution_test.go +++ b/senderDepositoryInstitution_test.go @@ -130,7 +130,7 @@ func TestStringSenderDepositoryInstitutionVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringSenderDepositoryInstitutionOptions validates string() with options +// TestStringSenderDepositoryInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { var line = "{3100}1*A*" r := NewReader(strings.NewReader(line)) @@ -139,9 +139,8 @@ func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { err := r.parseSenderDepositoryInstitution() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.SenderDepositoryInstitution.String() - require.Equal(t, str, "{3100}1 A ") - - str = r.currentFEDWireMessage.SenderDepositoryInstitution.String(true) - require.Equal(t, str, "{3100}1*A*") + record := r.currentFEDWireMessage.SenderDepositoryInstitution + require.Equal(t, record.String(), "{3100}1 A ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}1*A*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderReference.go b/senderReference.go index 06e342bf..d3e9b6be 100644 --- a/senderReference.go +++ b/senderReference.go @@ -71,13 +71,20 @@ func (sr *SenderReference) UnmarshalJSON(data []byte) error { return nil } -// String writes SenderReference -func (sr *SenderReference) String(options ...bool) string { +// String returns a fixed-width SenderReference record +func (sr *SenderReference) String() string { + return sr.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a SenderReference record formatted according to the FormatOptions +func (sr *SenderReference) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(22) buf.WriteString(sr.tag) - buf.WriteString(sr.SenderReferenceField(options...)) + buf.WriteString(sr.FormatSenderReference(options)) return buf.String() } @@ -94,7 +101,7 @@ func (sr *SenderReference) Validate() error { return nil } -// SenderReferenceField gets a string of SenderReference field -func (sr *SenderReference) SenderReferenceField(options ...bool) string { - return sr.alphaVariableField(sr.SenderReference, 16, sr.parseFirstOption(options)) +// FormatSenderReference returns SenderReference formatted according to the FormatOptions +func (sr *SenderReference) FormatSenderReference(options FormatOptions) string { + return sr.formatAlphaField(sr.SenderReference, 16, options) } diff --git a/senderReference_test.go b/senderReference_test.go index 0475133e..eb7cd5a1 100644 --- a/senderReference_test.go +++ b/senderReference_test.go @@ -96,7 +96,7 @@ func TestStringSenderReferenceVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringSenderReferenceOptions validates string() with options +// TestStringSenderReferenceOptions validates Format() formatted according to the FormatOptions func TestStringSenderReferenceOptions(t *testing.T) { var line = "{3320}" r := NewReader(strings.NewReader(line)) @@ -105,9 +105,8 @@ func TestStringSenderReferenceOptions(t *testing.T) { err := r.parseSenderReference() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.SenderReference.String() - require.Equal(t, str, "{3320} ") - - str = r.currentFEDWireMessage.SenderReference.String(true) - require.Equal(t, str, "{3320}*") + record := r.currentFEDWireMessage.SenderReference + require.Equal(t, record.String(), "{3320} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3320}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderSupplied.go b/senderSupplied.go index 0ae71551..d40bf144 100644 --- a/senderSupplied.go +++ b/senderSupplied.go @@ -97,16 +97,23 @@ func (ss *SenderSupplied) UnmarshalJSON(data []byte) error { return nil } -// String writes SenderSupplied -func (ss *SenderSupplied) String(options ...bool) string { +// String returns a fixed-width SenderSupplied record +func (ss *SenderSupplied) String() string { + return ss.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a SenderSupplied record formatted according to the FormatOptions +func (ss *SenderSupplied) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(18) buf.WriteString(ss.tag) buf.WriteString(ss.FormatVersionField()) - buf.WriteString(ss.UserRequestCorrelationField(options...)) + buf.WriteString(ss.FormatUserRequestCorrelation(options)) buf.WriteString(ss.TestProductionCodeField()) - buf.WriteString(ss.MessageDuplicationCodeField(options...)) + buf.WriteString(ss.FormatMessageDuplicationCode(options)) return buf.String() } @@ -150,8 +157,8 @@ func (ss *SenderSupplied) FormatVersionField() string { } // UserRequestCorrelationField gets a string of the UserRequestCorrelation field -func (ss *SenderSupplied) UserRequestCorrelationField(options ...bool) string { - return ss.alphaVariableField(ss.UserRequestCorrelation, 8, ss.parseFirstOption(options)) +func (ss *SenderSupplied) UserRequestCorrelationField() string { + return ss.alphaField(ss.UserRequestCorrelation, 8) } // TestProductionCodeField gets a string of the TestProductionCoden field @@ -160,6 +167,16 @@ func (ss *SenderSupplied) TestProductionCodeField() string { } // MessageDuplicationCodeField gets a string of the MessageDuplicationCode field -func (ss *SenderSupplied) MessageDuplicationCodeField(options ...bool) string { - return ss.alphaVariableField(ss.MessageDuplicationCode, 1, ss.parseFirstOption(options)) +func (ss *SenderSupplied) MessageDuplicationCodeField() string { + return ss.alphaField(ss.MessageDuplicationCode, 1) +} + +// FormatUserRequestCorrelation returns UserRequestCorrelation formatted according to the FormatOptions +func (ss *SenderSupplied) FormatUserRequestCorrelation(options FormatOptions) string { + return ss.formatAlphaField(ss.UserRequestCorrelation, 8, options) +} + +// FormatMessageDuplicationCode returns MessageDuplicationCode formatted according to the FormatOptions +func (ss *SenderSupplied) FormatMessageDuplicationCode(options FormatOptions) string { + return ss.formatAlphaField(ss.MessageDuplicationCode, 1, options) } diff --git a/senderSupplied_test.go b/senderSupplied_test.go index d67325ee..3e60924d 100644 --- a/senderSupplied_test.go +++ b/senderSupplied_test.go @@ -144,7 +144,7 @@ func TestStringSenderSuppliedVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringSenderSuppliedOptions validates string() with options +// TestStringSenderSuppliedOptions validates Format() formatted according to the FormatOptions func TestStringSenderSuppliedOptions(t *testing.T) { var line = "{1500}301*T" r := NewReader(strings.NewReader(line)) @@ -153,9 +153,8 @@ func TestStringSenderSuppliedOptions(t *testing.T) { err := r.parseSenderSupplied() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.SenderSupplied.String() - require.Equal(t, str, "{1500}301 T ") - - str = r.currentFEDWireMessage.SenderSupplied.String(true) - require.Equal(t, str, "{1500}301*T*") + record := r.currentFEDWireMessage.SenderSupplied + require.Equal(t, record.String(), "{1500}301 T ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1500}301*T*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderToReceiver.go b/senderToReceiver.go index 2712c498..408101d5 100644 --- a/senderToReceiver.go +++ b/senderToReceiver.go @@ -113,21 +113,28 @@ func (str *SenderToReceiver) UnmarshalJSON(data []byte) error { return nil } -// String writes SenderToReceiver -func (str *SenderToReceiver) String(options ...bool) string { +// String returns a fixed-width SenderToReceiver record +func (str *SenderToReceiver) String() string { + return str.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a SenderToReceiver record formatted according to the FormatOptions +func (str *SenderToReceiver) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(221) buf.WriteString(str.tag) - buf.WriteString(str.SwiftFieldTagField(options...)) - buf.WriteString(str.SwiftLineOneField(options...)) - buf.WriteString(str.SwiftLineTwoField(options...)) - buf.WriteString(str.SwiftLineThreeField(options...)) - buf.WriteString(str.SwiftLineFourField(options...)) - buf.WriteString(str.SwiftLineFiveField(options...)) - buf.WriteString(str.SwiftLineSixField(options...)) - - if str.parseFirstOption(options) { + buf.WriteString(str.FormatSwiftFieldTag(options)) + buf.WriteString(str.FormatSwiftLineOne(options)) + buf.WriteString(str.FormatSwiftLineTwo(options)) + buf.WriteString(str.FormatSwiftLineThree(options)) + buf.WriteString(str.FormatSwiftLineFour(options)) + buf.WriteString(str.FormatSwiftLineFive(options)) + buf.WriteString(str.FormatSwiftLineSix(options)) + + if options.VariableLengthFields { return str.stripDelimiters(buf.String()) } else { return buf.String() @@ -165,36 +172,71 @@ func (str *SenderToReceiver) Validate() error { } // SwiftFieldTagField gets a string of the SwiftFieldTag field -func (str *SenderToReceiver) SwiftFieldTagField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftFieldTag, 5, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftFieldTagField() string { + return str.alphaField(str.CoverPayment.SwiftFieldTag, 5) } // SwiftLineOneField gets a string of the SwiftLineOne field -func (str *SenderToReceiver) SwiftLineOneField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineOne, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineOneField() string { + return str.alphaField(str.CoverPayment.SwiftLineOne, 35) } // SwiftLineTwoField gets a string of the SwiftLineTwo field -func (str *SenderToReceiver) SwiftLineTwoField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineTwo, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineTwoField() string { + return str.alphaField(str.CoverPayment.SwiftLineTwo, 35) } // SwiftLineThreeField gets a string of the SwiftLineThree field -func (str *SenderToReceiver) SwiftLineThreeField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineThree, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineThreeField() string { + return str.alphaField(str.CoverPayment.SwiftLineThree, 35) } // SwiftLineFourField gets a string of the SwiftLineFour field -func (str *SenderToReceiver) SwiftLineFourField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineFour, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineFourField() string { + return str.alphaField(str.CoverPayment.SwiftLineFour, 35) } // SwiftLineFiveField gets a string of the SwiftLineFive field -func (str *SenderToReceiver) SwiftLineFiveField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineFive, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineFiveField() string { + return str.alphaField(str.CoverPayment.SwiftLineFive, 35) } // SwiftLineSixField gets a string of the SwiftLineSix field -func (str *SenderToReceiver) SwiftLineSixField(options ...bool) string { - return str.alphaVariableField(str.CoverPayment.SwiftLineSix, 35, str.parseFirstOption(options)) +func (str *SenderToReceiver) SwiftLineSixField() string { + return str.alphaField(str.CoverPayment.SwiftLineSix, 35) +} + +// FormatSwiftFieldTag returns CoverPayment.SwiftFieldTag formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftFieldTag(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftFieldTag, 5, options) +} + +// FormatSwiftLineOne returns CoverPayment.SwiftLineOne formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineOne(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineOne, 35, options) +} + +// FormatSwiftLineTwo returns CoverPayment.SwiftLineTwo formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineTwo(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineTwo, 35, options) +} + +// FormatSwiftLineThree returns CoverPayment.SwiftLineThree formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineThree(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineThree, 35, options) +} + +// FormatSwiftLineFour returns CoverPayment.SwiftLineFour formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineFour(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineFour, 35, options) +} + +// FormatSwiftLineFive returns CoverPayment.SwiftLineFive formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineFive(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineFive, 35, options) +} + +// FormatSwiftLineSix returns CoverPayment.SwiftLineSix formatted according to the FormatOptions +func (str *SenderToReceiver) FormatSwiftLineSix(options FormatOptions) string { + return str.formatAlphaField(str.CoverPayment.SwiftLineSix, 35, options) } diff --git a/senderToReceiver_test.go b/senderToReceiver_test.go index f30d2b4d..165dc33a 100644 --- a/senderToReceiver_test.go +++ b/senderToReceiver_test.go @@ -162,7 +162,7 @@ func TestStringSenderToReceiverVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringSenderToReceiverOptions validates string() with options +// TestStringSenderToReceiverOptions validates Format() formatted according to the FormatOptions func TestStringSenderToReceiverOptions(t *testing.T) { var line = "{7072}" r := NewReader(strings.NewReader(line)) @@ -171,9 +171,8 @@ func TestStringSenderToReceiverOptions(t *testing.T) { err := r.parseSenderToReceiver() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.SenderToReceiver.String() - require.Equal(t, str, "{7072} ") - - str = r.currentFEDWireMessage.SenderToReceiver.String(true) - require.Equal(t, str, "{7072}*") + record := r.currentFEDWireMessage.SenderToReceiver + require.Equal(t, record.String(), "{7072} ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7072}*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/serviceMessage.go b/serviceMessage.go index 69b83eeb..6dfa7f0e 100644 --- a/serviceMessage.go +++ b/serviceMessage.go @@ -170,26 +170,33 @@ func (sm *ServiceMessage) UnmarshalJSON(data []byte) error { return nil } -// String writes ServiceMessage -func (sm *ServiceMessage) String(options ...bool) string { +// String returns a fixed-width ServiceMessage record +func (sm *ServiceMessage) String() string { + return sm.Format(FormatOptions{ + VariableLengthFields: false, + }) +} + +// Format returns a ServiceMessage record formatted according to the FormatOptions +func (sm *ServiceMessage) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(426) buf.WriteString(sm.tag) - buf.WriteString(sm.LineOneField(options...)) - buf.WriteString(sm.LineTwoField(options...)) - buf.WriteString(sm.LineThreeField(options...)) - buf.WriteString(sm.LineFourField(options...)) - buf.WriteString(sm.LineFiveField(options...)) - buf.WriteString(sm.LineSixField(options...)) - buf.WriteString(sm.LineSevenField(options...)) - buf.WriteString(sm.LineEightField(options...)) - buf.WriteString(sm.LineNineField(options...)) - buf.WriteString(sm.LineTenField(options...)) - buf.WriteString(sm.LineElevenField(options...)) - buf.WriteString(sm.LineTwelveField(options...)) - - if sm.parseFirstOption(options) { + buf.WriteString(sm.FormatLineOne(options)) + buf.WriteString(sm.FormatLineTwo(options)) + buf.WriteString(sm.FormatLineThree(options)) + buf.WriteString(sm.FormatLineFour(options)) + buf.WriteString(sm.FormatLineFive(options)) + buf.WriteString(sm.FormatLineSix(options)) + buf.WriteString(sm.FormatLineSeven(options)) + buf.WriteString(sm.FormatLineEight(options)) + buf.WriteString(sm.FormatLineNine(options)) + buf.WriteString(sm.FormatLineTen(options)) + buf.WriteString(sm.FormatLineEleven(options)) + buf.WriteString(sm.FormatLineTwelve(options)) + + if options.VariableLengthFields { return sm.stripDelimiters(buf.String()) } else { return buf.String() @@ -256,61 +263,121 @@ func (sm *ServiceMessage) fieldInclusion() error { } // LineOneField gets a string of the LineOne field -func (sm *ServiceMessage) LineOneField(options ...bool) string { - return sm.alphaVariableField(sm.LineOne, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineOneField() string { + return sm.alphaField(sm.LineOne, 35) } // LineTwoField gets a string of the LineTwo field -func (sm *ServiceMessage) LineTwoField(options ...bool) string { - return sm.alphaVariableField(sm.LineTwo, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineTwoField() string { + return sm.alphaField(sm.LineTwo, 35) } // LineThreeField gets a string of the LineThree field -func (sm *ServiceMessage) LineThreeField(options ...bool) string { - return sm.alphaVariableField(sm.LineThree, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineThreeField() string { + return sm.alphaField(sm.LineThree, 35) } // LineFourField gets a string of the LineFour field -func (sm *ServiceMessage) LineFourField(options ...bool) string { - return sm.alphaVariableField(sm.LineFour, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineFourField() string { + return sm.alphaField(sm.LineFour, 35) } // LineFiveField gets a string of the LineFive field -func (sm *ServiceMessage) LineFiveField(options ...bool) string { - return sm.alphaVariableField(sm.LineFive, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineFiveField() string { + return sm.alphaField(sm.LineFive, 35) } // LineSixField gets a string of the LineSix field -func (sm *ServiceMessage) LineSixField(options ...bool) string { - return sm.alphaVariableField(sm.LineSix, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineSixField() string { + return sm.alphaField(sm.LineSix, 35) } // LineSevenField gets a string of the LineSeven field -func (sm *ServiceMessage) LineSevenField(options ...bool) string { - return sm.alphaVariableField(sm.LineSeven, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineSevenField() string { + return sm.alphaField(sm.LineSeven, 35) } // LineEightField gets a string of the LineEight field -func (sm *ServiceMessage) LineEightField(options ...bool) string { - return sm.alphaVariableField(sm.LineEight, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineEightField() string { + return sm.alphaField(sm.LineEight, 35) } // LineNineField gets a string of the LineNine field -func (sm *ServiceMessage) LineNineField(options ...bool) string { - return sm.alphaVariableField(sm.LineNine, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineNineField() string { + return sm.alphaField(sm.LineNine, 35) } // LineTenField gets a string of the LineTen field -func (sm *ServiceMessage) LineTenField(options ...bool) string { - return sm.alphaVariableField(sm.LineTen, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineTenField() string { + return sm.alphaField(sm.LineTen, 35) } // LineElevenField gets a string of the LineEleven field -func (sm *ServiceMessage) LineElevenField(options ...bool) string { - return sm.alphaVariableField(sm.LineEleven, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineElevenField() string { + return sm.alphaField(sm.LineEleven, 35) } // LineTwelveField gets a string of the LineTwelve field -func (sm *ServiceMessage) LineTwelveField(options ...bool) string { - return sm.alphaVariableField(sm.LineTwelve, 35, sm.parseFirstOption(options)) +func (sm *ServiceMessage) LineTwelveField() string { + return sm.alphaField(sm.LineTwelve, 35) +} + +// FormatLineOne returns LineOne formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineOne(options FormatOptions) string { + return sm.formatAlphaField(sm.LineOne, 35, options) +} + +// FormatLineTwo returns LineTwo formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineTwo(options FormatOptions) string { + return sm.formatAlphaField(sm.LineTwo, 35, options) +} + +// FormatLineThree returns LineThree formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineThree(options FormatOptions) string { + return sm.formatAlphaField(sm.LineThree, 35, options) +} + +// FormatLineFour returns LineFour formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineFour(options FormatOptions) string { + return sm.formatAlphaField(sm.LineFour, 35, options) +} + +// FormatLineFive returns LineFive formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineFive(options FormatOptions) string { + return sm.formatAlphaField(sm.LineFive, 35, options) +} + +// FormatLineSix returns LineSix formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineSix(options FormatOptions) string { + return sm.formatAlphaField(sm.LineSix, 35, options) +} + +// FormatLineSeven returns LineSeven formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineSeven(options FormatOptions) string { + return sm.formatAlphaField(sm.LineSeven, 35, options) +} + +// FormatLineEight returns LineEight formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineEight(options FormatOptions) string { + return sm.formatAlphaField(sm.LineEight, 35, options) +} + +// FormatLineNine returns LineNine formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineNine(options FormatOptions) string { + return sm.formatAlphaField(sm.LineNine, 35, options) +} + +// FormatLineTen returns LineTen formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineTen(options FormatOptions) string { + return sm.formatAlphaField(sm.LineTen, 35, options) +} + +// FormatLineEleven returns LineEleven formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineEleven(options FormatOptions) string { + return sm.formatAlphaField(sm.LineEleven, 35, options) +} + +// FormatLineTwelve returns LineTwelve formatted according to the FormatOptions +func (sm *ServiceMessage) FormatLineTwelve(options FormatOptions) string { + return sm.formatAlphaField(sm.LineTwelve, 35, options) } diff --git a/serviceMessage_test.go b/serviceMessage_test.go index e66b59f4..a00a9d00 100644 --- a/serviceMessage_test.go +++ b/serviceMessage_test.go @@ -386,7 +386,7 @@ func TestStringServiceMessageVariableLength(t *testing.T) { require.Equal(t, err, nil) } -// TestStringServiceMessageOptions validates string() with options +// TestStringServiceMessageOptions validates Format() formatted according to the FormatOptions func TestStringServiceMessageOptions(t *testing.T) { var line = "{9000}A*" r := NewReader(strings.NewReader(line)) @@ -395,9 +395,8 @@ func TestStringServiceMessageOptions(t *testing.T) { err := r.parseServiceMessage() require.Equal(t, err, nil) - str := r.currentFEDWireMessage.ServiceMessage.String() - require.Equal(t, str, "{9000}A ") - - str = r.currentFEDWireMessage.ServiceMessage.String(true) - require.Equal(t, str, "{9000}A*") + record := r.currentFEDWireMessage.ServiceMessage + require.Equal(t, record.String(), "{9000}A ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{9000}A*") + require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/writer.go b/writer.go index f0613566..c2a0a9b8 100644 --- a/writer.go +++ b/writer.go @@ -16,10 +16,9 @@ import ( // Writer struct type Writer struct { - w *bufio.Writer - lineNum int //current line being written - variableLength bool - newlineChar string + w *bufio.Writer + lineNum int // current line being written + FormatOptions } type OptionFunc func(*Writer) @@ -27,22 +26,25 @@ type OptionFunc func(*Writer) // VariableLengthFields specify to support variable length func VariableLengthFields(variableLength bool) OptionFunc { return func(w *Writer) { - w.variableLength = variableLength + w.VariableLengthFields = variableLength } } // NewlineCharacter specify new line character func NewlineCharacter(newline string) OptionFunc { return func(w *Writer) { - w.newlineChar = newline + w.NewlineCharacter = newline } } // NewWriter returns a new Writer that writes to w. +// If no opts are provided, the writer will default to fixed-length fields and use "\n" for newlines. func NewWriter(w io.Writer, opts ...OptionFunc) *Writer { writer := &Writer{ - w: bufio.NewWriter(w), - newlineChar: "\n", + w: bufio.NewWriter(w), + FormatOptions: FormatOptions{ + NewlineCharacter: "\n", + }, } for _, opt := range opts { @@ -77,9 +79,6 @@ func (w *Writer) Flush() error { return w.w.Flush() } -// options -// first bool : has variable length -// second bool : has not new line func (w *Writer) writeFEDWireMessage(file *File) error { fwm := file.FEDWireMessage @@ -109,7 +108,7 @@ func (w *Writer) writeFEDWireMessage(file *File) error { } if fwm.UnstructuredAddenda != nil { - if _, err := w.w.WriteString(fwm.UnstructuredAddenda.String() + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.UnstructuredAddenda.String() + w.NewlineCharacter); err != nil { return err } } @@ -119,7 +118,7 @@ func (w *Writer) writeFEDWireMessage(file *File) error { } if fwm.ServiceMessage != nil { - if _, err := w.w.WriteString(fwm.ServiceMessage.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ServiceMessage.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -134,25 +133,25 @@ func (w *Writer) writeFEDWireMessage(file *File) error { func (w *Writer) writeFedAppended(fwm FEDWireMessage) error { if fwm.MessageDisposition != nil { - if _, err := w.w.WriteString(fwm.MessageDisposition.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.MessageDisposition.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.ReceiptTimeStamp != nil { - if _, err := w.w.WriteString(fwm.ReceiptTimeStamp.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ReceiptTimeStamp.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OutputMessageAccountabilityData != nil { - if _, err := w.w.WriteString(fwm.OutputMessageAccountabilityData.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OutputMessageAccountabilityData.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.ErrorWire != nil { - if _, err := w.w.WriteString(fwm.ErrorWire.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ErrorWire.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -163,7 +162,7 @@ func (w *Writer) writeFedAppended(fwm FEDWireMessage) error { func (w *Writer) writeMandatory(fwm FEDWireMessage) error { if fwm.SenderSupplied != nil { - if _, err := w.w.WriteString(fwm.SenderSupplied.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.SenderSupplied.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } else { @@ -171,7 +170,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.TypeSubType != nil { - if _, err := w.w.WriteString(fwm.TypeSubType.String() + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.TypeSubType.String() + w.NewlineCharacter); err != nil { return err } } else { @@ -179,7 +178,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.InputMessageAccountabilityData != nil { - if _, err := w.w.WriteString(fwm.InputMessageAccountabilityData.String() + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.InputMessageAccountabilityData.String() + w.NewlineCharacter); err != nil { return err } } else { @@ -187,7 +186,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.Amount != nil { - if _, err := w.w.WriteString(fwm.Amount.String() + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Amount.String() + w.NewlineCharacter); err != nil { return err } } else { @@ -195,7 +194,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.SenderDepositoryInstitution != nil { - if _, err := w.w.WriteString(fwm.SenderDepositoryInstitution.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.SenderDepositoryInstitution.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } else { @@ -203,7 +202,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.ReceiverDepositoryInstitution != nil { - if _, err := w.w.WriteString(fwm.ReceiverDepositoryInstitution.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ReceiverDepositoryInstitution.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } else { @@ -211,7 +210,7 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { } if fwm.BusinessFunctionCode != nil { - if _, err := w.w.WriteString(fwm.BusinessFunctionCode.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.BusinessFunctionCode.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } else { @@ -224,43 +223,43 @@ func (w *Writer) writeMandatory(fwm FEDWireMessage) error { func (w *Writer) writeOtherTransferInfo(fwm FEDWireMessage) error { if fwm.SenderReference != nil { - if _, err := w.w.WriteString(fwm.SenderReference.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.SenderReference.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.PreviousMessageIdentifier != nil { - if _, err := w.w.WriteString(fwm.PreviousMessageIdentifier.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.PreviousMessageIdentifier.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.LocalInstrument != nil { - if _, err := w.w.WriteString(fwm.LocalInstrument.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.LocalInstrument.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.PaymentNotification != nil { - if _, err := w.w.WriteString(fwm.PaymentNotification.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.PaymentNotification.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.Charges != nil { - if _, err := w.w.WriteString(fwm.Charges.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Charges.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.InstructedAmount != nil { - if _, err := w.w.WriteString(fwm.InstructedAmount.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.InstructedAmount.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.ExchangeRate != nil { - if _, err := w.w.WriteString(fwm.ExchangeRate.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ExchangeRate.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -271,14 +270,14 @@ func (w *Writer) writeOtherTransferInfo(fwm FEDWireMessage) error { func (w *Writer) writeBeneficiary(fwm FEDWireMessage) error { if fwm.BeneficiaryIntermediaryFI != nil { - if _, err := w.w.WriteString(fwm.BeneficiaryIntermediaryFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.BeneficiaryIntermediaryFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.BeneficiaryFI != nil { if fwm.BeneficiaryFI != nil { - if _, err := w.w.WriteString(fwm.BeneficiaryFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.BeneficiaryFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -286,7 +285,7 @@ func (w *Writer) writeBeneficiary(fwm FEDWireMessage) error { if fwm.Beneficiary != nil { if fwm.Beneficiary != nil { - if _, err := w.w.WriteString(fwm.Beneficiary.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Beneficiary.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -294,7 +293,7 @@ func (w *Writer) writeBeneficiary(fwm FEDWireMessage) error { if fwm.BeneficiaryReference != nil { if fwm.BeneficiaryReference != nil { - if _, err := w.w.WriteString(fwm.BeneficiaryReference.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.BeneficiaryReference.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -302,7 +301,7 @@ func (w *Writer) writeBeneficiary(fwm FEDWireMessage) error { if fwm.AccountDebitedDrawdown != nil { if fwm.AccountDebitedDrawdown != nil { - if _, err := w.w.WriteString(fwm.AccountDebitedDrawdown.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.AccountDebitedDrawdown.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -314,37 +313,37 @@ func (w *Writer) writeBeneficiary(fwm FEDWireMessage) error { func (w *Writer) writeOriginator(fwm FEDWireMessage) error { if fwm.Originator != nil { - if _, err := w.w.WriteString(fwm.Originator.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Originator.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OriginatorOptionF != nil { - if _, err := w.w.WriteString(fwm.OriginatorOptionF.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OriginatorOptionF.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OriginatorFI != nil { - if _, err := w.w.WriteString(fwm.OriginatorFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OriginatorFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.InstructingFI != nil { - if _, err := w.w.WriteString(fwm.InstructingFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.InstructingFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.AccountCreditedDrawdown != nil { - if _, err := w.w.WriteString(fwm.AccountCreditedDrawdown.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.AccountCreditedDrawdown.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OriginatorToBeneficiary != nil { - if _, err := w.w.WriteString(fwm.OriginatorToBeneficiary.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OriginatorToBeneficiary.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -355,61 +354,61 @@ func (w *Writer) writeOriginator(fwm FEDWireMessage) error { func (w *Writer) writeFinancialInstitution(fwm FEDWireMessage) error { if fwm.FIReceiverFI != nil { - if _, err := w.w.WriteString(fwm.FIReceiverFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIReceiverFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIDrawdownDebitAccountAdvice != nil { - if _, err := w.w.WriteString(fwm.FIDrawdownDebitAccountAdvice.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIDrawdownDebitAccountAdvice.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIIntermediaryFI != nil { - if _, err := w.w.WriteString(fwm.FIIntermediaryFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIIntermediaryFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIIntermediaryFIAdvice != nil { - if _, err := w.w.WriteString(fwm.FIIntermediaryFIAdvice.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIIntermediaryFIAdvice.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIBeneficiaryFI != nil { - if _, err := w.w.WriteString(fwm.FIBeneficiaryFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIBeneficiaryFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIBeneficiaryFIAdvice != nil { - if _, err := w.w.WriteString(fwm.FIBeneficiaryFIAdvice.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIBeneficiaryFIAdvice.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIBeneficiary != nil { - if _, err := w.w.WriteString(fwm.FIBeneficiary.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIBeneficiary.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIBeneficiaryAdvice != nil { - if _, err := w.w.WriteString(fwm.FIBeneficiaryAdvice.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIBeneficiaryAdvice.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIPaymentMethodToBeneficiary != nil { - if _, err := w.w.WriteString(fwm.FIPaymentMethodToBeneficiary.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIPaymentMethodToBeneficiary.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.FIAdditionalFIToFI != nil { - if _, err := w.w.WriteString(fwm.FIAdditionalFIToFI.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.FIAdditionalFIToFI.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -420,49 +419,49 @@ func (w *Writer) writeFinancialInstitution(fwm FEDWireMessage) error { func (w *Writer) writeCoverPayment(fwm FEDWireMessage) error { if fwm.CurrencyInstructedAmount != nil { - if _, err := w.w.WriteString(fwm.CurrencyInstructedAmount.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.CurrencyInstructedAmount.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OrderingCustomer != nil { - if _, err := w.w.WriteString(fwm.OrderingCustomer.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OrderingCustomer.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.OrderingInstitution != nil { - if _, err := w.w.WriteString(fwm.OrderingInstitution.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.OrderingInstitution.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.IntermediaryInstitution != nil { - if _, err := w.w.WriteString(fwm.IntermediaryInstitution.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.IntermediaryInstitution.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.InstitutionAccount != nil { - if _, err := w.w.WriteString(fwm.InstitutionAccount.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.InstitutionAccount.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.BeneficiaryCustomer != nil { - if _, err := w.w.WriteString(fwm.BeneficiaryCustomer.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.BeneficiaryCustomer.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.Remittance != nil { - if _, err := w.w.WriteString(fwm.Remittance.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Remittance.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.SenderToReceiver != nil { - if _, err := w.w.WriteString(fwm.SenderToReceiver.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.SenderToReceiver.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } @@ -474,68 +473,68 @@ func (w *Writer) writeRemittance(fwm FEDWireMessage) error { // Related Remittance if fwm.RelatedRemittance != nil { - if _, err := w.w.WriteString(fwm.RelatedRemittance.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.RelatedRemittance.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } // Structured Remittance if fwm.RemittanceOriginator != nil { - if _, err := w.w.WriteString(fwm.RemittanceOriginator.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.RemittanceOriginator.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.RemittanceBeneficiary != nil { - if _, err := w.w.WriteString(fwm.RemittanceBeneficiary.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.RemittanceBeneficiary.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.PrimaryRemittanceDocument != nil { - if _, err := w.w.WriteString(fwm.PrimaryRemittanceDocument.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.PrimaryRemittanceDocument.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.ActualAmountPaid != nil { - if _, err := w.w.WriteString(fwm.ActualAmountPaid.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.ActualAmountPaid.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.GrossAmountRemittanceDocument != nil { - if _, err := w.w.WriteString(fwm.GrossAmountRemittanceDocument.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.GrossAmountRemittanceDocument.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.AmountNegotiatedDiscount != nil { - if _, err := w.w.WriteString(fwm.AmountNegotiatedDiscount.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.AmountNegotiatedDiscount.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.Adjustment != nil { - if _, err := w.w.WriteString(fwm.Adjustment.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.Adjustment.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.DateRemittanceDocument != nil { - if _, err := w.w.WriteString(fwm.DateRemittanceDocument.String() + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.DateRemittanceDocument.String() + w.NewlineCharacter); err != nil { return err } } if fwm.SecondaryRemittanceDocument != nil { - if _, err := w.w.WriteString(fwm.SecondaryRemittanceDocument.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.SecondaryRemittanceDocument.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } } if fwm.RemittanceFreeText != nil { - if _, err := w.w.WriteString(fwm.RemittanceFreeText.String(w.variableLength) + w.newlineChar); err != nil { + if _, err := w.w.WriteString(fwm.RemittanceFreeText.Format(w.FormatOptions) + w.NewlineCharacter); err != nil { return err } }