metawards.Interpret

class metawards.Interpret[source]

This is a static class that provides some routines for interpreting values from inputs (normally strings). This is used heavily by code that reads values from the user or from files

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

boolean(s[, rng]) Interpret and return a boolean (True or False) using the passed random number generator if this is a request for a random boolean
date(s, allow_fuzzy) Return a Python datetime.date object from the passed ‘s’, allowing fuzzy dates if ‘allow_fuzzy’ is true
day(s[, rng]) Return a day number (integer) from the passed ‘s’.
day_or_date(s[, rng]) Convenience function that matches a day or a date from the passed ‘s’
integer(s[, rng]) Interpret and return an integer from ‘s’, using the passed random number generator if this is a request for a random integer, and within the specified bounds of ‘minval’ and ‘maxval’ if needed.
number(s[, rng]) Interpret and return a number (integer or float) using the passed random number generator if this is a request for a random number, and within the specified bound of ‘minval’ and ‘maxval’ is needed
random_integer(s[, rng]) Interpret a random integer from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values
random_number(s[, rng]) Interpret a random number (float) from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values
string(s) Interpret and return a string from ‘s’
static boolean(s: any, rng=None) → bool[source]

Interpret and return a boolean (True or False) using the passed random number generator if this is a request for a random boolean

static date(s: any, allow_fuzzy: bool = True)[source]

Return a Python datetime.date object from the passed ‘s’, allowing fuzzy dates if ‘allow_fuzzy’ is true

static day(s: any, rng=None, minval: int = None, maxval: int = None) → int[source]

Return a day number (integer) from the passed ‘s’. This is a shorthand for ‘integer’, but may take on more meaning if the day needs to be more specialised

static day_or_date(s: any, rng=None, minval: int = None, maxval: int = None, allow_fuzzy: bool = True)[source]

Convenience function that matches a day or a date from the passed ‘s’

static integer(s: any, rng=None, minval: int = None, maxval: int = None) → int[source]

Interpret and return an integer from ‘s’, using the passed random number generator if this is a request for a random integer, and within the specified bounds of ‘minval’ and ‘maxval’ if needed.

This can interpret ‘s’ as an expression, e.g. “6 / 3” etc.

static number(s: any, rng=None, minval: Union[int, float] = None, maxval: Union[int, float] = None) → Union[int, float][source]

Interpret and return a number (integer or float) using the passed random number generator if this is a request for a random number, and within the specified bound of ‘minval’ and ‘maxval’ is needed

This can interpret ‘s’ as an expression, e.g. “2.4 * 3.6” etc.

static random_integer(s: str = None, rng=None, minval: int = None, maxval: int = None) → int[source]

Interpret a random integer from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

static random_number(s: str = None, rng=None, minval: float = None, maxval: float = None) → float[source]

Interpret a random number (float) from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

static string(s: any) → str[source]

Interpret and return a string from ‘s’