numberer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MinuteFactory is a factory to produce valid minute values
	MinuteFactory = Must(NewFactory("minute", 0, 59))

	// HourFactory is a factory to produce valid hour values
	HourFactory = Must(NewFactory("hour", 0, 23))

	// DayOfMonthFactory is a factory to produce valid day of month values
	DayOfMonthFactory = Must(NewFactory("dayOfMonth", 1, 31))

	// MonthFactory is a factory to produce valid month values
	MonthFactory = Must(NewFactory("month", 1, 12))

	// DayOfWeekFactory is a factory that can produce valid day of week values
	DayOfWeekFactory = Must(NewFactory("dayOfWeek", 0, 6))
)

Functions

This section is empty.

Types

type Any

type Any []int

Any is a type that can be filled with all the numbers from a range

func (Any) Numbers

func (a Any) Numbers() []int

Numbers implements Numberer and will return all of the values it contains

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory is a type that can create Numberers for different strings

func Must

func Must(factory Factory, err error) Factory

Must will panic if an error is passed to it, used for factory variables

func NewFactory

func NewFactory(name string, start, end int) (Factory, error)

NewFactory will create a new factory for a given range, with a name, the name is used for errors.

func (Factory) Any

func (f Factory) Any() Any

Any will return a Numberer that will return the entire range of numbers

func (Factory) Number

func (f Factory) Number(numstr string) (Number, error)

Number will create a Number Numberer from a string, and validate that it is within the range of the factory (along with validating that the input is an int)

func (Factory) Range

func (f Factory) Range(startString, endString string) (Range, error)

Range will create a range from the given strings, validating that the range that they within the range of the factory (along with validating that the inputs is an int)

type Number

type Number int

Number is a Numberer that will return a single number

func (Number) Numbers

func (n Number) Numbers() []int

Numbers implements Numberer and will return the number as an array of numbers

type Provider

type Provider interface {
	Number(numstr string) (Number, error)
	Range(startString, endString string) (Range, error)
	Any() Any
}

Provider is an interface to abstract the Factory

type Range

type Range struct {
	Start, End int
}

Range is a Numberer that will return all of the numbers in a given range

func NewRange

func NewRange(start, end int) (Range, error)

NewRange will create a new Range, validating that the end is greater than the end

func (Range) Numbers

func (r Range) Numbers() []int

Numbers implements Numberer that will return all of the numbers between the start and end values

Jump to

Keyboard shortcuts

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