<commit_before>part of irc;

class WhoisBuilder {
  static final List<String> FIELDS = [
    "nickname",
    "realname",
    "hostname",
    "username",
    "away_message",
    "away",
    "channels",
    "op_in",
    "voice_in",
    "server_name",
    "server_info",
    "idle",
    "idle_time",
    "server_operator"
  ];

  final String nickname;
  String username;
  String realname;
  String hostname;
  String away_message;
  List<String> channels = [];
  List<String> voice_in = [];
  List<String> op_in = [];
  String server_name;
  String server_info;
  bool idle;
  int idle_time;
  bool server_operator;
  bool away = false;

  WhoisBuilder(this.nickname);

  @override
  String toString() {
    var sb = new StringBuffer("WHOIS(");
    for (String field in FIELDS) {
      var last = FIELDS.last == field;
      var obj = reflect(this).getField(MirrorSystem.getSymbol(field)).reflectee;
      sb
        ..write(field)
        ..write(": ")
        ..write("${obj}");
      if (!last)
        sb.write(", ");
    }
    sb.write(")");
    return sb.toString();
  }
}<commit_msg>WhoisBuilder: Remove field names storage and use introspection instead.<commit_after>part of irc;

class WhoisBuilder {
  final String nickname;
  String username;
  String realname;
  String hostname;
  String away_message;
  List<String> channels = [];
  List<String> voice_in = [];
  List<String> op_in = [];
  String server_name;
  String server_info;
  bool idle;
  int idle_time;
  bool server_operator;
  bool away = false;

  WhoisBuilder(this.nickname);

  @override
  String toString() {
    var instance = reflect(this);
    var sb = new StringBuffer("WHOIS(");
    var fields = instance.type.declarations.values.where((f) => f is VariableMirror && !f.isPrivate);
    var names = fields.map((f) => MirrorSystem.getName(f.simpleName));
    for (String field in names) {
      var last = names.last == field;
      var obj = instance.getField(MirrorSystem.getSymbol(field)).reflectee;
      sb
        ..write(field)
        ..write(": ")
        ..write("${obj}");
      if (!last)
        sb.write(", ");
    }
    sb.write(")");
    return sb.toString();
  }
}
{'fraction_non_alphanumeric': 0.14252660805182785, 'fraction_numerical': 0.0, 'mean_word_length': 2.8884892086330933, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581469', 'n_tokens_mistral': 714, 'n_tokens_neox': 707, 'n_words': 170}