Decorator to convert the units the function arguments. The syntax is equal to `Processor` except that strings are interpreted as units. >>> conv = ToQuantityProcessor('ms') >>> conv(Q_(1, 's')) >>> conv(1) <Quantity(
| 203 | |
| 204 | |
| 205 | class ToQuantityProcessor(Processor): |
| 206 | """Decorator to convert the units the function arguments. |
| 207 | |
| 208 | The syntax is equal to `Processor` except that strings are interpreted |
| 209 | as units. |
| 210 | |
| 211 | >>> conv = ToQuantityProcessor('ms') |
| 212 | >>> conv(Q_(1, 's')) |
| 213 | <Quantity(1000.0, 'millisecond')> |
| 214 | >>> conv(1) |
| 215 | <Quantity(1.0, 'millisecond')> |
| 216 | |
| 217 | """ |
| 218 | |
| 219 | @classmethod |
| 220 | def to_callable(cls, obj): |
| 221 | if isinstance(obj, (str, Q_)): |
| 222 | return convert_to(obj, on_dimensionless='ignore') |
| 223 | raise TypeError('ToQuantityProcessor argument must be a string ' |
| 224 | ' or a callable, not {}'.format(obj)) |
| 225 | |
| 226 | |
| 227 | class ParseProcessor(Processor): |