GatorConfig.fromYaml constructor

GatorConfig.fromYaml(
  1. YamlMap yamlMap
)

The configuration that represents the YAML document.

Example yaml:

gator:
  class: MyColors
  colors:
    royalBlue: '0xff062091'
    grey: '#ffd6d6d6'

There the gator and colors entries are required from the YAML document.

Implementation

factory GatorConfig.fromYaml(YamlMap yamlMap) {
  if (yamlMap case {'gator': {'colors': final YamlMap yamlColors}}) {
    ConfigColor toConfigColor(dynamic colorKey) {
      return ConfigColor.fromHex(
        hex: '${yamlColors[colorKey]}',
        name: '$colorKey',
      );
    }

    final outputPath = switch (yamlMap['gator']) {
      {'output': final String? output} => output,
      _ => null,
    };

    final className = switch (yamlMap['gator']) {
      {'class': final String className} => className,
      _ => 'MyColors',
    };

    return GatorConfig(
      colors: yamlColors.keys.map<ConfigColor>(toConfigColor),
      outputPath: outputPath,
      className: className,
    );
  }

  throw InvalidGatorConfigException();
}