rules.dart 788 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. - GEOSITE,geolocation-!cn,proxy
  3. - GEOSITE,cn,DIRECT
  4. - GEOIP,CN,DIRECT
  5. - MATCH,proxy
  6. */
  7. class Rule {
  8. final String type;
  9. final String? condition;
  10. final String action;
  11. Rule({
  12. required this.type,
  13. this.condition,
  14. required this.action,
  15. });
  16. factory Rule.fromMap(Map<String, dynamic> map) {
  17. return Rule(
  18. type: map['type'],
  19. condition: map['condition'],
  20. action: map['action'],
  21. );
  22. }
  23. Map<String, dynamic> toJson() {
  24. return {
  25. 'type': type,
  26. 'condition': condition,
  27. 'action': action,
  28. };
  29. }
  30. String toYaml() {
  31. // 当 condition 不为空时,包括 condition,否则省略 condition
  32. String conditionPart = condition != null ? ',$condition' : '';
  33. return ' - $type$conditionPart,$action';
  34. }
  35. }