2020-05-27 21:23:36 +02:00
|
|
|
package feragstring
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// TitleInfo is the struct for the FERAG title info message (%2440)
|
2020-05-27 21:23:36 +02:00
|
|
|
type TitleInfo struct {
|
|
|
|
FeragMessage
|
2020-05-29 14:22:16 +02:00
|
|
|
printObjectName string
|
|
|
|
titleName string
|
|
|
|
publicationDate time.Time
|
2023-03-24 17:04:31 +01:00
|
|
|
issueReference string
|
2020-05-29 14:22:16 +02:00
|
|
|
countryCode string
|
|
|
|
printObjectColor string
|
|
|
|
additionalInfo string
|
|
|
|
showEmptyAdditionalInfo bool
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// ShowEmptyAdditionalInfo sets the flag showEmptyAdditionalInfo to true.
|
|
|
|
// The segment additional info is then shown even it is empty (+08).
|
2020-05-29 14:22:16 +02:00
|
|
|
func (ti *TitleInfo) ShowEmptyAdditionalInfo() {
|
|
|
|
ti.showEmptyAdditionalInfo = true
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetPrintObjectName sets the printObjectName segment (+93)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetPrintObjectName(printObjectName string) {
|
|
|
|
ti.printObjectName = printObjectName
|
|
|
|
}
|
|
|
|
|
2020-05-29 15:09:16 +02:00
|
|
|
// AdditionalInfo returns the additional info segment (+08) FERAG-formatted.
|
|
|
|
// It is not returned if empty UNLESS the flag showEmptyAdditionalInfo is
|
|
|
|
// set to true.
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) AdditionalInfo() string {
|
2020-05-29 14:22:16 +02:00
|
|
|
if ti.additionalInfo == "" && ti.showEmptyAdditionalInfo == false {
|
2020-05-29 11:02:33 +02:00
|
|
|
return ""
|
|
|
|
}
|
2020-05-27 21:23:36 +02:00
|
|
|
return fmt.Sprintf("+08%-50s", ti.additionalInfo)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetAdditionalInfo sets the additional info segment (+08)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetAdditionalInfo(additionalInfo string) {
|
|
|
|
ti.additionalInfo = additionalInfo
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// PrintObjectColor returns the print object color segment (+94) FERAG-formatted
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) PrintObjectColor() string {
|
2020-05-29 11:02:33 +02:00
|
|
|
if ti.printObjectColor == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2020-05-27 21:23:36 +02:00
|
|
|
return fmt.Sprintf("+94%-8s", ti.printObjectColor)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetPrintObjectColor sets the print object color segment (+94)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetPrintObjectColor(printObjectColor string) {
|
|
|
|
ti.printObjectColor = printObjectColor
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// CountryCode returns the country code segment (+97) FERAG-formatted
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) CountryCode() string {
|
2020-05-29 11:02:33 +02:00
|
|
|
if ti.countryCode == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2020-05-27 21:23:36 +02:00
|
|
|
return fmt.Sprintf("+97%-2s", ti.countryCode)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetCountryCode set the country code segment (+97)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetCountryCode(countryCode string) {
|
|
|
|
ti.countryCode = countryCode
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetPublicationDate sets the publication date segment (+95)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetPublicationDate(publicationDateString string) {
|
|
|
|
parsedDate, err := time.Parse(dateInputFormatISO, publicationDateString)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
ti.publicationDate = parsedDate
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// PublicationDate returns the publication date segment (+95) FERAG-formatted
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) PublicationDate() string {
|
2020-05-29 11:02:33 +02:00
|
|
|
if ti.publicationDate.IsZero() {
|
|
|
|
return ""
|
|
|
|
}
|
2020-05-27 21:23:36 +02:00
|
|
|
return fmt.Sprintf("+95%-6s", ti.publicationDate.Format(dateOutputFormat))
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// Message returns the complete FERAG-formatted message for title info
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) Message() string {
|
|
|
|
message := ti.FeragMessage.MessageTemplate()
|
|
|
|
return message(&ti.FeragMessage, ti.Payload())
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// Payload returns the inner content for title info to be included in Message()
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) Payload() string {
|
|
|
|
data := ti.PrintObjectName()
|
|
|
|
data += ti.TitleName()
|
|
|
|
data += ti.PublicationDate()
|
2023-03-24 17:04:31 +01:00
|
|
|
data += ti.IssueReference()
|
2020-05-27 21:23:36 +02:00
|
|
|
data += ti.CountryCode()
|
|
|
|
data += ti.PrintObjectColor()
|
|
|
|
data += ti.AdditionalInfo()
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2023-03-24 17:04:31 +01:00
|
|
|
func (ti *TitleInfo) SetIssueReference(issueReference string) {
|
|
|
|
ti.issueReference = issueReference
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ti *TitleInfo) IssueReference() string {
|
|
|
|
if ti.issueReference == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("+99195%8s", ti.issueReference)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// PrintObjectName returns the print object name segment (+93) FERAG-formatted
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) PrintObjectName() string {
|
2020-05-29 11:02:33 +02:00
|
|
|
if ti.printObjectName == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2020-05-27 21:23:36 +02:00
|
|
|
return fmt.Sprintf("+93%-12s", ti.printObjectName)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// TitleName returns the title name segment (+40) FERAG-formatted
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) TitleName() string {
|
2020-07-06 20:18:58 +02:00
|
|
|
return fmt.Sprintf("+40%-8.8s", ti.titleName)
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// SetTitleName sets the title name segment (+40)
|
2020-05-27 21:23:36 +02:00
|
|
|
func (ti *TitleInfo) SetTitleName(titleName string) {
|
|
|
|
ti.titleName = titleName
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:54:45 +02:00
|
|
|
// NewTitleInfo returns a new TitleInfo struct
|
2020-05-27 21:23:36 +02:00
|
|
|
func NewTitleInfo() *TitleInfo {
|
|
|
|
t := TitleInfo{
|
2020-05-29 14:22:16 +02:00
|
|
|
FeragMessage: FeragMessage{"2440", "!"},
|
|
|
|
showEmptyAdditionalInfo: false,
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
return &t
|
|
|
|
}
|