Change function names to Decode to make them more accurate

This commit is contained in:
Elara 2023-08-22 19:19:15 -07:00
parent a1dfd6629f
commit 2c16694cec
3 changed files with 20 additions and 20 deletions

View File

@ -52,7 +52,7 @@ func main() {
fl = os.Stdin fl = os.Stdin
} }
fc, err := taf.ParseWithOptions(fl, opts) fc, err := taf.DecodeWithOptions(fl, opts)
if err != nil { if err != nil {
log.Fatal("Error parsing TAF data").Err(err).Send() log.Fatal("Error parsing TAF data").Err(err).Send()
} }

28
taf.go
View File

@ -16,32 +16,32 @@ import (
"go.elara.ws/taf/units" "go.elara.ws/taf/units"
) )
// ParseString parses a TAF string and returns a Forecast. // DecodeString decodes a TAF string and returns a Forecast.
// This is equivalent to Parse(strings.NewReader(s)). // This is equivalent to Decode(strings.NewReader(s)).
func ParseString(s string) (*Forecast, error) { func DecodeString(s string) (*Forecast, error) {
return Parse(strings.NewReader(s)) return Decode(strings.NewReader(s))
} }
// ParseFile parses a TAF string and returns a Forecast. // DecodeFile decodes a TAF string and returns a Forecast.
// This is equivalent to opening a file and passing it // This is equivalent to opening a file and passing it
// to Parse(). // to Decode().
func ParseFile(path string) (*Forecast, error) { func DecodeFile(path string) (*Forecast, error) {
fl, err := os.Open(path) fl, err := os.Open(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer fl.Close() defer fl.Close()
return Parse(fl) return Decode(fl)
} }
// Parse parses the data in a reader using default options and // Decode decodes the data in a reader using default options and
// returns a Forecast // returns a Forecast
func Parse(r io.Reader) (*Forecast, error) { func Decode(r io.Reader) (*Forecast, error) {
return ParseWithOptions(r, Options{}) return DecodeWithOptions(r, Options{})
} }
// Options contains options for the parser // Options contains options for the decoder
type Options struct { type Options struct {
// If this is set, all distance units in the forecast // If this is set, all distance units in the forecast
// will be converted to the given unit // will be converted to the given unit
@ -60,8 +60,8 @@ type Options struct {
Month time.Month Month time.Month
} }
// ParseWithOptions parses the data in a reader and returns a Forecast // DecodeWithOptions decodes the data in a reader and returns a Forecast
func ParseWithOptions(r io.Reader, opts Options) (*Forecast, error) { func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
filename := "unknown" filename := "unknown"
switch r := r.(type) { switch r := r.(type) {
case *os.File: case *os.File:

View File

@ -188,7 +188,7 @@ func TestKLAX(t *testing.T) {
}, },
} }
fc, err := ParseWithOptions(strings.NewReader(data), Options{ fc, err := DecodeWithOptions(strings.NewReader(data), Options{
Month: time.August, Month: time.August,
Year: 2023, Year: 2023,
}) })
@ -309,7 +309,7 @@ func TestZGSZ(t *testing.T) {
}, },
} }
fc, err := ParseWithOptions(strings.NewReader(data), Options{ fc, err := DecodeWithOptions(strings.NewReader(data), Options{
Month: time.August, Month: time.August,
Year: 2023, Year: 2023,
}) })
@ -435,7 +435,7 @@ func TestLFBD(t *testing.T) {
}, },
} }
fc, err := ParseWithOptions(strings.NewReader(data), Options{ fc, err := DecodeWithOptions(strings.NewReader(data), Options{
Month: time.August, Month: time.August,
Year: 2023, Year: 2023,
}) })
@ -580,7 +580,7 @@ func TestUUEE(t *testing.T) {
}, },
} }
fc, err := ParseWithOptions(strings.NewReader(data), Options{ fc, err := DecodeWithOptions(strings.NewReader(data), Options{
Month: time.August, Month: time.August,
Year: 2023, Year: 2023,
}) })
@ -688,7 +688,7 @@ func TestEGLL(t *testing.T) {
}, },
} }
fc, err := ParseWithOptions(strings.NewReader(data), Options{ fc, err := DecodeWithOptions(strings.NewReader(data), Options{
Month: time.August, Month: time.August,
Year: 2023, Year: 2023,
}) })