Added comment to title info

This commit is contained in:
Oliver Jakoubek 2020-05-29 14:54:45 +02:00
parent fddb9bd53e
commit 5c415c5aac

View file

@ -5,6 +5,7 @@ import (
"time" "time"
) )
// TitleInfo is the struct for the FERAG title info message (%2440)
type TitleInfo struct { type TitleInfo struct {
FeragMessage FeragMessage
printObjectName string printObjectName string
@ -16,14 +17,18 @@ type TitleInfo struct {
showEmptyAdditionalInfo bool showEmptyAdditionalInfo bool
} }
// ShowEmptyAdditionalInfo sets the flag showEmptyAdditionalInfo to true.
// The segment additional info is then shown even it is empty (+08).
func (ti *TitleInfo) ShowEmptyAdditionalInfo() { func (ti *TitleInfo) ShowEmptyAdditionalInfo() {
ti.showEmptyAdditionalInfo = true ti.showEmptyAdditionalInfo = true
} }
// SetPrintObjectName sets the printObjectName segment (+93)
func (ti *TitleInfo) SetPrintObjectName(printObjectName string) { func (ti *TitleInfo) SetPrintObjectName(printObjectName string) {
ti.printObjectName = printObjectName ti.printObjectName = printObjectName
} }
// AdditionalInfo returns the additional info segment (+08) FERAG-formatted
func (ti *TitleInfo) AdditionalInfo() string { func (ti *TitleInfo) AdditionalInfo() string {
if ti.additionalInfo == "" && ti.showEmptyAdditionalInfo == false { if ti.additionalInfo == "" && ti.showEmptyAdditionalInfo == false {
return "" return ""
@ -31,10 +36,12 @@ func (ti *TitleInfo) AdditionalInfo() string {
return fmt.Sprintf("+08%-50s", ti.additionalInfo) return fmt.Sprintf("+08%-50s", ti.additionalInfo)
} }
// SetAdditionalInfo sets the additional info segment (+08)
func (ti *TitleInfo) SetAdditionalInfo(additionalInfo string) { func (ti *TitleInfo) SetAdditionalInfo(additionalInfo string) {
ti.additionalInfo = additionalInfo ti.additionalInfo = additionalInfo
} }
// PrintObjectColor returns the print object color segment (+94) FERAG-formatted
func (ti *TitleInfo) PrintObjectColor() string { func (ti *TitleInfo) PrintObjectColor() string {
if ti.printObjectColor == "" { if ti.printObjectColor == "" {
return "" return ""
@ -42,10 +49,12 @@ func (ti *TitleInfo) PrintObjectColor() string {
return fmt.Sprintf("+94%-8s", ti.printObjectColor) return fmt.Sprintf("+94%-8s", ti.printObjectColor)
} }
// SetPrintObjectColor sets the print object color segment (+94)
func (ti *TitleInfo) SetPrintObjectColor(printObjectColor string) { func (ti *TitleInfo) SetPrintObjectColor(printObjectColor string) {
ti.printObjectColor = printObjectColor ti.printObjectColor = printObjectColor
} }
// CountryCode returns the country code segment (+97) FERAG-formatted
func (ti *TitleInfo) CountryCode() string { func (ti *TitleInfo) CountryCode() string {
if ti.countryCode == "" { if ti.countryCode == "" {
return "" return ""
@ -53,10 +62,12 @@ func (ti *TitleInfo) CountryCode() string {
return fmt.Sprintf("+97%-2s", ti.countryCode) return fmt.Sprintf("+97%-2s", ti.countryCode)
} }
// SetCountryCode set the country code segment (+97)
func (ti *TitleInfo) SetCountryCode(countryCode string) { func (ti *TitleInfo) SetCountryCode(countryCode string) {
ti.countryCode = countryCode ti.countryCode = countryCode
} }
// SetPublicationDate sets the publication date segment (+95)
func (ti *TitleInfo) SetPublicationDate(publicationDateString string) { func (ti *TitleInfo) SetPublicationDate(publicationDateString string) {
parsedDate, err := time.Parse(dateInputFormatISO, publicationDateString) parsedDate, err := time.Parse(dateInputFormatISO, publicationDateString)
if err != nil { if err != nil {
@ -65,6 +76,7 @@ func (ti *TitleInfo) SetPublicationDate(publicationDateString string) {
ti.publicationDate = parsedDate ti.publicationDate = parsedDate
} }
// PublicationDate returns the publication date segment (+95) FERAG-formatted
func (ti *TitleInfo) PublicationDate() string { func (ti *TitleInfo) PublicationDate() string {
if ti.publicationDate.IsZero() { if ti.publicationDate.IsZero() {
return "" return ""
@ -72,11 +84,13 @@ func (ti *TitleInfo) PublicationDate() string {
return fmt.Sprintf("+95%-6s", ti.publicationDate.Format(dateOutputFormat)) return fmt.Sprintf("+95%-6s", ti.publicationDate.Format(dateOutputFormat))
} }
// Message returns the complete FERAG-formatted message for title info
func (ti *TitleInfo) Message() string { func (ti *TitleInfo) Message() string {
message := ti.FeragMessage.MessageTemplate() message := ti.FeragMessage.MessageTemplate()
return message(&ti.FeragMessage, ti.Payload()) return message(&ti.FeragMessage, ti.Payload())
} }
// Payload returns the inner content for title info to be included in Message()
func (ti *TitleInfo) Payload() string { func (ti *TitleInfo) Payload() string {
data := ti.PrintObjectName() data := ti.PrintObjectName()
data += ti.TitleName() data += ti.TitleName()
@ -87,6 +101,7 @@ func (ti *TitleInfo) Payload() string {
return data return data
} }
// PrintObjectName returns the print object name segment (+93) FERAG-formatted
func (ti *TitleInfo) PrintObjectName() string { func (ti *TitleInfo) PrintObjectName() string {
if ti.printObjectName == "" { if ti.printObjectName == "" {
return "" return ""
@ -94,14 +109,17 @@ func (ti *TitleInfo) PrintObjectName() string {
return fmt.Sprintf("+93%-12s", ti.printObjectName) return fmt.Sprintf("+93%-12s", ti.printObjectName)
} }
// TitleName returns the title name segment (+40) FERAG-formatted
func (ti *TitleInfo) TitleName() string { func (ti *TitleInfo) TitleName() string {
return fmt.Sprintf("+40%-8s", ti.titleName) return fmt.Sprintf("+40%-8s", ti.titleName)
} }
// SetTitleName sets the title name segment (+40)
func (ti *TitleInfo) SetTitleName(titleName string) { func (ti *TitleInfo) SetTitleName(titleName string) {
ti.titleName = titleName ti.titleName = titleName
} }
// NewTitleInfo returns a new TitleInfo struct
func NewTitleInfo() *TitleInfo { func NewTitleInfo() *TitleInfo {
t := TitleInfo{ t := TitleInfo{
FeragMessage: FeragMessage{"2440", "!"}, FeragMessage: FeragMessage{"2440", "!"},