2020-05-27 21:23:36 +02:00
|
|
|
package feragstring
|
|
|
|
|
|
|
|
const (
|
|
|
|
dateInputFormatISO = "2006-01-02"
|
2020-05-29 14:39:59 +02:00
|
|
|
dateOutputFormat = "060102"
|
|
|
|
linebreak = "\r\n"
|
2020-05-27 21:23:36 +02:00
|
|
|
)
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// FeragString is the root struct for creating
|
|
|
|
// a FERAG string. One FeragString instance returns
|
|
|
|
// the output for one FERAG string.
|
2020-05-27 21:23:36 +02:00
|
|
|
type FeragString struct {
|
2020-05-29 14:39:59 +02:00
|
|
|
TitleInfo *TitleInfo
|
|
|
|
TitleEnd *TitleEnd
|
|
|
|
ProductReferences []*ProductReference
|
|
|
|
ProductReferencesNr int
|
2020-06-25 22:14:41 +02:00
|
|
|
Routes []*Route
|
|
|
|
RouteCount int
|
2020-05-29 14:39:59 +02:00
|
|
|
RouteListEntries []*RouteListEntry
|
|
|
|
RouteListEntryCount int
|
|
|
|
RouteInfoEntries []*RouteInfo
|
2020-05-29 11:02:33 +02:00
|
|
|
ProductionDropEntries []*ProductionDrop
|
2020-05-29 14:39:59 +02:00
|
|
|
RouteEndEntries []*RouteEnd
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// NewFeragString instantiates a new FeragString
|
|
|
|
// struct and returns a pointer to it.
|
2020-05-27 21:23:36 +02:00
|
|
|
func NewFeragString() *FeragString {
|
|
|
|
fs := FeragString{
|
|
|
|
TitleInfo: NewTitleInfo(),
|
2020-05-29 14:39:59 +02:00
|
|
|
TitleEnd: NewTitleEnd(),
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
return &fs
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// SetTitleName sets the title name field
|
2020-05-27 21:23:36 +02:00
|
|
|
func (fs *FeragString) SetTitleName(titleName string) {
|
|
|
|
fs.TitleInfo.SetTitleName(titleName)
|
|
|
|
fs.TitleEnd.SetTitleName(titleName)
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// PrintOut returns the final FERAG string of the FeragString instance
|
2020-05-27 21:23:36 +02:00
|
|
|
func (fs *FeragString) PrintOut() string {
|
2020-05-29 14:39:59 +02:00
|
|
|
// +2440 | first message is the title info
|
2020-05-27 21:23:36 +02:00
|
|
|
info := fs.TitleInfo.Message()
|
|
|
|
|
2020-05-29 14:39:59 +02:00
|
|
|
// +2450 | list of product references
|
2020-05-27 21:23:36 +02:00
|
|
|
for _, pr := range fs.ProductReferences {
|
|
|
|
info += pr.Message()
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:14:41 +02:00
|
|
|
// create route list entries for every route
|
|
|
|
for _, rt := range fs.Routes {
|
|
|
|
info += rt.GetRouteListEntry().Message()
|
2020-05-27 21:23:36 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:14:41 +02:00
|
|
|
// create route info for every route
|
|
|
|
// including embedded production drops
|
|
|
|
for _, rt := range fs.Routes {
|
|
|
|
info += rt.GetRouteMessage()
|
2020-05-29 11:02:33 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:14:41 +02:00
|
|
|
//for _, rl := range fs.RouteListEntries {
|
|
|
|
// info += rl.Message()
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//for _, ri := range fs.RouteInfoEntries {
|
|
|
|
// info += ri.Message()
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//for _, pd := range fs.ProductionDropEntries {
|
|
|
|
// info += pd.Message()
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//for _, re := range fs.RouteEndEntries {
|
|
|
|
// info += re.Message()
|
|
|
|
//}
|
2020-05-29 11:02:33 +02:00
|
|
|
|
2020-05-29 14:39:59 +02:00
|
|
|
// +2441 | last message is the corresponding title end
|
2020-05-27 21:23:36 +02:00
|
|
|
info += fs.TitleEnd.Message()
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// AddProductReference adds a Product Reference instance to the list
|
|
|
|
// of product references of the FeragString
|
2020-05-27 21:23:36 +02:00
|
|
|
func (fs *FeragString) AddProductReference(pr *ProductReference) error {
|
|
|
|
fs.ProductReferencesNr++
|
|
|
|
pr.SetProductReferenceNumber(fs.ProductReferencesNr)
|
|
|
|
if pr.productReferenceNumber == 1 && pr.productUsageType == 0 {
|
|
|
|
pr.SetProductUsageType(1)
|
|
|
|
}
|
|
|
|
fs.ProductReferences = append(fs.ProductReferences, pr)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// AddRoute adds a Route to the list of routes of the FeragString
|
2020-06-25 22:14:41 +02:00
|
|
|
func (fs *FeragString) AddRoute(r *Route) error {
|
|
|
|
fs.RouteCount++
|
|
|
|
fs.Routes = append(fs.Routes, r)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// NextRouteCode returns the next numeric route code.
|
|
|
|
// Use this method to get an automatically incremented
|
|
|
|
// counter value for the routes of a FeragString.
|
2020-06-25 22:14:41 +02:00
|
|
|
func (fs *FeragString) NextRouteCode() int {
|
|
|
|
return fs.RouteCount + 1
|
|
|
|
//return fs.RouteListEntryCount + 1
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// Deprecated: AddRouteListEntry adds a route list entry to a FeragString.
|
|
|
|
// Use AddRoute instead.
|
2020-05-27 21:23:36 +02:00
|
|
|
func (fs *FeragString) AddRouteListEntry(rl *RouteListEntry) error {
|
|
|
|
fs.RouteListEntryCount++
|
2020-05-29 11:02:33 +02:00
|
|
|
//if rl.routeCode == 0 {
|
|
|
|
// rl.SetRouteCode(fs.RouteListEntryCount)
|
|
|
|
//}
|
2020-05-27 21:23:36 +02:00
|
|
|
fs.RouteListEntries = append(fs.RouteListEntries, rl)
|
|
|
|
return nil
|
2020-05-29 11:02:33 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// Deprecated: AddRouteInfo adds a route info to a FeragString.
|
|
|
|
// Use AddRoute instead.
|
2020-05-29 11:02:33 +02:00
|
|
|
func (fs *FeragString) AddRouteInfo(ri *RouteInfo) error {
|
|
|
|
fs.RouteInfoEntries = append(fs.RouteInfoEntries, ri)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// Deprecated: AddProductionDrop adds a ProductionDrop to a FeragString.
|
|
|
|
// Use AddProductionDrop on the route struct instead.
|
2020-05-29 11:02:33 +02:00
|
|
|
func (fs *FeragString) AddProductionDrop(pd *ProductionDrop) error {
|
|
|
|
fs.ProductionDropEntries = append(fs.ProductionDropEntries, pd)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:27:05 +02:00
|
|
|
// Deprecated: AddRouteEnd adds a Route End to a FeragString.
|
|
|
|
// Not necessary anymore. Routes are automatically ended now.
|
2020-05-29 11:02:33 +02:00
|
|
|
func (fs *FeragString) AddRouteEnd(re *RouteEnd) error {
|
|
|
|
fs.RouteEndEntries = append(fs.RouteEndEntries, re)
|
|
|
|
return nil
|
2020-05-29 14:39:59 +02:00
|
|
|
}
|