Rational.parse constructor
Rational.parse(
- String source
Parses source as a Rational.
Implementation
factory Rational.parse(String source) {
final match = _regExp.firstMatch(source);
if (match == null || match[0] == null) {
return throw FormatException('Invalid Ratio', source);
}
final integer = int.parse(match.namedGroup('integer')!);
if (match.namedGroup('numerator') == null) {
return Rational.fromMixed(integer);
}
final numerator = int.parse(match.namedGroup('numerator')!);
final denominator = int.parse(match.namedGroup('denominator')!);
return Rational.fromMixed(integer, numerator, denominator);
}