Inheritance |
|
This pattern matching object can be used to test if values fall in a certain range or set of values, or to produce an array of values from a pattern.
Methods ¶
__init__(pattern, delimiter=' ')
Constructs a new pattern object from the specified pattern
string.
The delimiter
determines the character that separates different components
of the pattern. By default, components are separated by a space – for
example the pattern 1-4 6 9
generates the array [1, 2, 3, 7, 9]
.
Alternatively, if delimiter
is set to ,
instead, the pattern components
can be separated by commas: 1-4,6,9
.
componentRange(component, inclusive=False)
→ list
of float
Returns the range of values in the specified pattern component as an list of three floating point values.
componentStep(component)
→ float
Returns the range step value for the specified pattern component. If the
component does not have an explicit step, a value of 1
is always returned
instead.
contains(value, inclusive=False)
→ bool
Returns True if the specified value is in the pattern, or false if it is
not. By default, ranges are inclusive for the first value in the range and
exclude the last value in the range. If the inclusive
argument is set to
True
instead, the last value will also be included in the range.
containsRange(value, inclusive=False)
→ list
of float
The same as contains
, however instead of returning a boolean value the
method returns the [start, end, step]
values for the first matching
component that contained value
.
floatArray(sorted=True, inclusive=False)
→ list
of float
Returns the float array values for the pattern. If sorted
is True
the
values are sorted in ascending numeric order. The inclusive
argument
determines if the pattern should include the right endpoints for ranges
when generating the values in the float array.
floatArrayMap(sorted=True, inclusive=False)
→ dict
of list
of float
Same as floatArray
, but instead of a flat array this method returns a map
of component number to the array of values from that pattern component.
intArray(sorted=True, inclusive=False)
→ list
of int
Returns the int array values for the pattern. If sorted
is True
the
values are sorted in ascending numeric order. The inclusive
argument
determines if the pattern should include the right endpoints for ranges
when generating the values in the integer array.
intArrayMap(sorted=True, inclusive=False)
→ dict
of list
of int
Same as intArray
, but instead of a flat array this method returns a map
of component number to the array of values from that pattern component.
stringArray(sorted=True, inclusive=False)
→ list
of str
Returns the string array values for the pattern. If sorted
is True
the
values are sorted in ascending natural sorder order. The inclusive
argument
determines if the pattern should include the right endpoints for ranges
when generating the values in the string array.
stringArrayMap(sorted=True, inclusive=False)
→ dict
of list
of int
Same as stringArray
, but instead of a flat array this method returns a map
of component number to the array of values from that pattern component.
hasVariableStep
: bool
Property
Set to True
if the pattern is numeric and contains multiple components with different step sizes. For example, 1-10:2 4-8:0.3
.
isNumeric
: bool
Property
Set to True
if the pattern only contains numeric values. If any of the components in the pattern are a non-numeric string, isNumeric
will be set to False
.
minimumStep
: float
Property
Returns the minimum step size from all of the components in the pattern.
Methods from pdg.BasePattern ¶
errors
: str
Property
If the pattern is invalid, this string contains the parse errors.
isValid
: bool
Property
Set to True if the pattern is valid, else False.
pattern
: str
Property
The source string used to construct this pattern object.