parser

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package parser can parse CSV records into Protobuf quotes. It provides tools to parse dates, cents, or entire record.

Index

Constants

View Source
const MinYear = 1870

MinYear is the minimal supported year. Any date before the first day of this year is considered invalid.

Variables

View Source
var (
	// ErrNoDate means date value is missing in the record.
	ErrNoDate = errors.New("missing date")

	// ErrDate means the date value has invalid format (####.##) or incorrect,
	// e.g. not a number or the year is below [MinYear]. October is an exception
	// to the date format, it is represented by ####.1.
	ErrDate = errors.New("invalid date")

	// ErrYear means the date has invalid year
	ErrYear = errors.New("invalid year")

	// ErrMonth means the date has invalid month.
	ErrMonth = errors.New("invalid month")
)
View Source
var (
	// ErrNoSPX means SPX value is missing in the record.
	ErrNoSPX = errors.New("missing SPX")

	// ErrSPX means SPX value has invalid format. It should be ####.## with
	// dollar and cents.
	ErrSPX = errors.New("invalid SPX")
)
View Source
var (
	// ErrNoDividend means Dividend value is missing in the record.
	ErrNoDividend = errors.New("missing dividend")

	// ErrDividend means Dividend value has invalid format. See [ErrSPX] for
	// format description.
	ErrDividend = errors.New("invalid dividend")
)
View Source
var (
	// ErrNoEarnings means Earnings are missing in the record.
	ErrNoEarnings = errors.New("missing CPI")

	// ErrEarnings means Earnings has invalid format. See [ErrSPX] for
	// format description.
	ErrEarnings = errors.New("invalid CPI")
)
View Source
var (
	// ErrNoCPI means Consumer Price Index is missing in the record.
	ErrNoCPI = errors.New("missing CPI")

	// ErrCPI means Consumer Price Index has invalid format. See [ErrSPX] for
	// format description.
	ErrCPI = errors.New("invalid CPI")
)
View Source
var (
	// ErrFormat means the field has invalid format.
	ErrFormat = errors.New("invalid format")

	// ErrDollar means dollar part of the value in ####.## fails to parse.
	ErrDollar = errors.New("invalid dollar")

	// ErrCent means cent part of the value in ####.## fails to parse.
	ErrCent = errors.New("invalid cent")
)

Functions

func ParseCent

func ParseCent(s string) (*pb.Cent, error)

ParseCent parses string ####.## as cents. It returns an error if the value has invalid format such as cents or dollars are missing, the cents must have two digits, or the value is not a number.

func ParseDate

func ParseDate(s string) (*pb.Date, error)

ParseDate parses date string ####.## into year, month, and the last day of the month. The year has minimum threshold of MinYear. The month is in the range (1, 12) inclusive, represented by two digits except October, which is given by .1, e.g. 1990.1 is Oct 1990. It returns an error if parsing fails.

func ParseQuote

func ParseQuote(rec []string) (*pb.Quote, error)

ParseQuote converts a CSV record (row) into a quote. It returns and error if the row is invalid, i.e. it misses fields or the fields are invalid.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL