SenseInfo.fromXmlElement constructor

SenseInfo.fromXmlElement(
  1. XmlElement data
)

Implementation

factory SenseInfo.fromXmlElement(XmlElement data) {
  final definition =
      data.getElement(ApiXmlElement.definition.name)!.innerText.trim();
  final reference =
      data.getElement(ApiXmlElement.reference.name)?.innerText.trim();

  var aux = data.getElement(ApiXmlElement.patternInfo.name);
  final patternInfo = aux == null ? null : PatternInfo.fromXmlElement(aux);

  aux = data.getElement(ApiXmlElement.relatedInfo.name);
  final relatedInfo = aux == null ? null : RelatedInfo.fromXmlElement(aux);

  final translations = data
      .findElements(ApiXmlElement.translation.name)
      .map(Translation.fromXmlElement)
      .toList()
      .asMap()
      .map<TranslationLanguage, DictionaryDefinitionTranslation>(
        (_, translation) => MapEntry(
          TranslationLanguage.fromHangul(translation.language!.hangul)!,
          DictionaryDefinitionTranslation.fromTranslation(translation),
        ),
      );

  final examples = data
      .findElements(ApiXmlElement.exampleInfo.name)
      .map(ExampleInfo.fromXmlElement)
      .toList();

  return SenseInfo(
    definition: definition,
    translations: translations,
    reference: reference,
    patternInfo: patternInfo,
    relatedInfo: relatedInfo,
    examples: examples,
  );
}