QuestionRegisterConfig.parse constructor
QuestionRegisterConfig.parse(
- String yamlText
Reads a configuration: prefixes (a list), groups (a list of
{key, label, prefix, from?, to?}) and statuses (a list of
{key, label, waiting?}); each missing key keeps its default.
Implementation
factory QuestionRegisterConfig.parse(String yamlText) {
final root = loadYaml(yamlText);
if (root is! YamlMap) return defaults;
final prefixes = root['prefixes'] is YamlList
? [for (final p in root['prefixes'] as YamlList) '$p']
: defaults.prefixes;
final groups = root['groups'] is YamlList
? [
for (final g in root['groups'] as YamlList)
QuestionRegisterGroup(
key: '${(g as YamlMap)['key']}',
label: '${g['label']}',
prefix: '${g['prefix']}',
from: g['from'] as int?,
to: g['to'] as int?,
),
]
: defaults.groups;
final statuses = root['statuses'] is YamlList
? [
for (final st in root['statuses'] as YamlList)
QuestionRegisterStatus(
'${(st as YamlMap)['key']}',
'${st['label'] ?? st['key']}',
waiting: st['waiting'] == true,
),
]
: defaults.statuses;
return QuestionRegisterConfig(
prefixes: prefixes,
groups: groups,
statuses: statuses,
);
}