43 lines
1.0 KiB
Dart

import 'package:brick_generator/models/variable_syntax.dart';
import 'package:brick_generator/models/variable_type.dart';
import 'package:yaml/yaml.dart';
const _variableNameKey = 'variable_name';
const _typeKey = 'type';
const _syntaxKey = 'syntax';
class BrickVariable {
String? name;
VariabelType? type;
VariableSyntax? syntax;
BrickVariable({
required this.name,
required this.type,
required this.syntax,
});
BrickVariable._();
factory BrickVariable.parser() => BrickVariable._();
static BrickVariable? from(YamlMap? data) => data != null
? BrickVariable(
name: data[_variableNameKey] as String?,
type: VariabelType.stringToEnum(data[_typeKey] as String?),
syntax: VariableSyntax.from(data[_syntaxKey] as YamlMap?),
)
: null;
void checkFormat() {
if (name == null || type == null) {
throw ArgumentError(
'Yaml file is not conform',
);
}
if (type == VariabelType.string) {
syntax?.checkFormat();
}
}
}