feragstring/title_info.go

112 lines
2.5 KiB
Go
Raw Normal View History

2020-05-27 21:23:36 +02:00
package feragstring
import (
"fmt"
"time"
)
type TitleInfo struct {
FeragMessage
printObjectName string
titleName string
publicationDate time.Time
countryCode string
printObjectColor string
additionalInfo string
showEmptyAdditionalInfo bool
}
func (ti *TitleInfo) ShowEmptyAdditionalInfo() {
ti.showEmptyAdditionalInfo = true
2020-05-27 21:23:36 +02:00
}
func (ti *TitleInfo) SetPrintObjectName(printObjectName string) {
ti.printObjectName = printObjectName
}
func (ti *TitleInfo) AdditionalInfo() string {
if ti.additionalInfo == "" && ti.showEmptyAdditionalInfo == false {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+08%-50s", ti.additionalInfo)
}
func (ti *TitleInfo) SetAdditionalInfo(additionalInfo string) {
ti.additionalInfo = additionalInfo
}
func (ti *TitleInfo) PrintObjectColor() string {
if ti.printObjectColor == "" {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+94%-8s", ti.printObjectColor)
}
func (ti *TitleInfo) SetPrintObjectColor(printObjectColor string) {
ti.printObjectColor = printObjectColor
}
func (ti *TitleInfo) CountryCode() string {
if ti.countryCode == "" {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+97%-2s", ti.countryCode)
}
func (ti *TitleInfo) SetCountryCode(countryCode string) {
ti.countryCode = countryCode
}
func (ti *TitleInfo) SetPublicationDate(publicationDateString string) {
parsedDate, err := time.Parse(dateInputFormatISO, publicationDateString)
if err != nil {
panic(err)
}
ti.publicationDate = parsedDate
}
func (ti *TitleInfo) PublicationDate() string {
if ti.publicationDate.IsZero() {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+95%-6s", ti.publicationDate.Format(dateOutputFormat))
}
func (ti *TitleInfo) Message() string {
message := ti.FeragMessage.MessageTemplate()
return message(&ti.FeragMessage, ti.Payload())
}
func (ti *TitleInfo) Payload() string {
data := ti.PrintObjectName()
data += ti.TitleName()
data += ti.PublicationDate()
data += ti.CountryCode()
data += ti.PrintObjectColor()
data += ti.AdditionalInfo()
return data
}
func (ti *TitleInfo) PrintObjectName() string {
if ti.printObjectName == "" {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+93%-12s", ti.printObjectName)
}
func (ti *TitleInfo) TitleName() string {
return fmt.Sprintf("+40%-8s", ti.titleName)
}
func (ti *TitleInfo) SetTitleName(titleName string) {
ti.titleName = titleName
}
func NewTitleInfo() *TitleInfo {
t := TitleInfo{
FeragMessage: FeragMessage{"2440", "!"},
showEmptyAdditionalInfo: false,
2020-05-27 21:23:36 +02:00
}
return &t
}