Add report type
This commit is contained in:
parent
15be73cbc5
commit
cf76638b8a
11
convert.go
11
convert.go
@ -1,5 +1,16 @@
|
||||
package taf
|
||||
|
||||
func convertReportType(s string) ReportType {
|
||||
switch s {
|
||||
case "AMD":
|
||||
return Amended
|
||||
case "COR":
|
||||
return Corrected
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func convertSkyConditionType(s string) SkyConditionType {
|
||||
switch s {
|
||||
case "FEW":
|
||||
|
@ -5,7 +5,8 @@ import (
|
||||
)
|
||||
|
||||
var lex = lexer.MustSimple([]lexer.SimpleRule{
|
||||
{Name: "header", Pattern: `TAF (AMD|COR)? ?`},
|
||||
{Name: "header", Pattern: `TAF ?`},
|
||||
{Name: "Type", Pattern: "AMD|COR"},
|
||||
{Name: "Remark", Pattern: `RMK[^\n]*`},
|
||||
{Name: "Number", Pattern: `\d+`},
|
||||
{Name: "Modifier", Pattern: `[+-]|VC`},
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type AST struct {
|
||||
Type *string `(@Type WS)?`
|
||||
Items []*Item `@@*`
|
||||
}
|
||||
|
||||
|
4
taf.go
4
taf.go
@ -92,6 +92,10 @@ func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
|
||||
fc := &Forecast{}
|
||||
out := reflect.ValueOf(fc).Elem()
|
||||
|
||||
if ast.Type != nil {
|
||||
fc.ReportType = convertReportType(*ast.Type)
|
||||
}
|
||||
|
||||
for _, item := range ast.Items {
|
||||
switch {
|
||||
case item.ID != nil:
|
||||
|
@ -207,6 +207,7 @@ func TestZGSZ(t *testing.T) {
|
||||
TEMPO 2204/2208 TSRA SCT020 FEW023CB`
|
||||
|
||||
expected := &Forecast{
|
||||
ReportType: Amended,
|
||||
Identifier: "ZGSZ",
|
||||
Airport: airports.Airport{
|
||||
ICAO: "ZGSZ",
|
||||
|
13
types.go
13
types.go
@ -9,6 +9,9 @@ import (
|
||||
|
||||
// Forecast represents a Terminal Aerodrome Forecast (TAF) weather report for a specific airport.
|
||||
type Forecast struct {
|
||||
// ReportType represents the type of report this forecast describes.
|
||||
ReportType ReportType `json:"report_type,omitempty"`
|
||||
|
||||
// Identifier holds the ICAO airport identifier for which this forecast was issued.
|
||||
Identifier string `json:"identifier,omitempty"`
|
||||
|
||||
@ -130,6 +133,16 @@ type Visibility struct {
|
||||
Unit units.Distance `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
// ReportType represents different types of reports.
|
||||
type ReportType string
|
||||
|
||||
const (
|
||||
// Amended represents a report issued when the previous report is no longer accurate.
|
||||
Amended ReportType = "Amended"
|
||||
// Corrected represents a correction to a previous report.
|
||||
Corrected ReportType = "Corrected"
|
||||
)
|
||||
|
||||
// SkyConditionType represents different types of sky conditions in the forecast.
|
||||
type SkyConditionType string
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user