Fraction.fromGlyph constructor

Fraction.fromGlyph(
  1. String value
)

Returns an instance of Fraction if the source string is a glyph representing a fraction.

A 'glyph' (or 'number form') is an unicode character that represents a fraction. For example, the glyph for "1/7" is ⅐. Only a very small subset of fractions have a glyph representation.

Fraction.fromString("⅐") // 1/7
Fraction.fromString("⅔") // 2/3
Fraction.fromString("⅞") // 7/8

If the given string value doesn't represent a fraction glyph, then an instance of FractionException is thrown.

Implementation

factory Fraction.fromGlyph(String value) {
  if (_glyphsToValues.containsKey(value)) {
    return _glyphsToValues[value]!;
  }

  throw FractionException(
    'The given string ($value) does not represent a valid fraction glyph!',
  );
}