Release.fromXml constructor
- XmlElement xml, {
- Language? language,
Constructs a Release from the provided XmlElement.
If xml
contains language attributes specified for description
, then
this will try to use the language
specified (or English, if null
).
Implementation
factory Release.fromXml(XmlElement xml, {Language? language}) {
language ??= L10n.languages.first;
String title = xml.findElements('title').first.innerText;
// Omit the leading `v` of the release version, if any.
if (title.startsWith('v')) {
title = title.substring(1);
}
final String? description =
xml
.findElements('description')
.firstWhereOrNull(
(e) => e.attributes.any(
(p) =>
p.name.qualified == 'xml:lang' &&
p.value == language?.toString(),
),
)
?.innerText ??
xml.findElements('description').firstOrNull?.innerText;
final String date = xml.findElements('pubDate').first.innerText;
final List<ReleaseArtifact> assets =
xml
.findElements('enclosure')
.map((e) => ReleaseArtifact.fromXml(e))
.toList();
return Release(
name: title,
description: (description?.isEmpty ?? true) ? null : description?.trim(),
publishedAt: Rfc822ToDateTime.tryParse(date) ?? DateTime.now(),
assets: assets,
);
}