ViewItem.fromXmlElement constructor

ViewItem.fromXmlElement(
  1. XmlElement data
)

"channel" xml element.

Implementation

factory ViewItem.fromXmlElement(XmlElement data) {
  final item = data.findAllElements(ApiXmlElement.item.name).first;
  final link = data.getElement(ApiXmlElement.link.name)!.innerText.trim();
  final targetCode = int.parse(
    item.getElement(ApiXmlElement.targetCode.name)!.innerText.trim(),
  );
  final wordInfo = item.getElement(ApiXmlElement.wordInfo.name)!;
  final word = wordInfo.getElement(ApiXmlElement.word.name)!.innerText.trim();
  final supNo = int.parse(
    wordInfo.getElement(ApiXmlElement.supNo.name)!.innerText.trim(),
  );
  String? aux = wordInfo.getElement(ApiXmlElement.pos.name)!.innerText.trim();
  final pos = PartOfSpeech.fromHangul(aux);
  aux = wordInfo.getElement(ApiXmlElement.wordGrade.name)?.innerText.trim();
  final wordGrade = WordGrade.fromHangul(aux ?? '');
  aux = wordInfo.getElement(ApiXmlElement.wordUnit.name)!.innerText.trim();
  final wordUnit = WordUnit.fromHangul(aux)!;
  aux = wordInfo.getElement(ApiXmlElement.wordType.name)!.innerText.trim();
  final wordType = WordType.fromHangul(aux)!;
  final pronunciations = wordInfo
      .findElements(ApiXmlElement.pronunciationInfo.name)
      .map(PronunciationInfo.fromXmlElement)
      .toList();
  final origins = wordInfo
      .findElements(ApiXmlElement.originalLanguageInfo.name)
      .map(
        (e) => OriginalLanguageInfo.fromXmlElement(
          e,
          word: word,
          wordType: wordType,
        ),
      )
      .toList();
  final conjugations = wordInfo
      .findElements(ApiXmlElement.conjuInfo.name)
      .map(ConjugationInfo.fromXmlElement)
      .toList()
    ..removeWhere((e) => e.conjugation.isEmpty);
  final abbreviations = wordInfo
      .findElements(ApiXmlElement.abbreviationInfo.name)
      .map(AbbreviationInfo.fromXmlElement)
      .toList();
  final references = wordInfo
      .findElements(ApiXmlElement.refInfo.name)
      .map(ReferenceInfo.fromXmlElement)
      .toList();
  final categories = wordInfo
      .findElements(ApiXmlElement.categoryInfo.name)
      .map(CategoryInfo.fromXmlElement)
      .toList();
  final derivatives = wordInfo
      .findElements(ApiXmlElement.derInfo.name)
      .map(DerivativeInfo.fromXmlElement)
      .toList();
  final senses = wordInfo
      .findElements(ApiXmlElement.senseInfo.name)
      .map(SenseInfo.fromXmlElement)
      .toList();
  final subwords = wordInfo
      .findElements(ApiXmlElement.subwordInfo.name)
      .map(SubwordInfo.fromXmlElement)
      .toList();

  return ViewItem(
    targetCode: targetCode,
    word: word,
    supNo: supNo,
    pos: pos,
    link: link,
    wordGrade: wordGrade,
    wordUnit: wordUnit,
    wordType: wordType,
    origins: origins,
    pronunciations: pronunciations,
    abbreviations: abbreviations,
    references: references,
    categories: categories,
    conjugations: conjugations,
    derivatives: derivatives,
    senses: senses,
    subwords: subwords,
  );
}