Currency.code constructor

Currency.code(
  1. String code
)

Find currency by XXX ISO-4217 code

Case insensitive

Returns UnknownCurrency if fails

Implementation

factory Currency.code(
  /// XXX code to look for
  String code,
) {
  final upperCode = code.toUpperCase();
  final info = Iso4217.firstWhere((currency) => currency['code'] == upperCode,
      orElse: () => <String, dynamic>{});

  if (!info.containsKey('code')) return UnknownCurrency(code);

  return Currency(
    info['code'] as String,
    info['number'] as int,
    info['digits'] as int,
  );
}