Syndication.parse constructor

Syndication.parse(
  1. XmlElement element
)

Parse constructor for the Syndication class, used when 'parsing' a feed

Implementation

factory Syndication.parse(XmlElement element) {
  SyndicationUpdatePeriod updatePeriod;
  switch (element.findElements('sy:updatePeriod').firstOrNull?.innerText) {
    case 'hourly':
      updatePeriod = SyndicationUpdatePeriod.hourly;
    case 'daily':
      updatePeriod = SyndicationUpdatePeriod.daily;
    case 'weekly':
      updatePeriod = SyndicationUpdatePeriod.weekly;
    case 'monthly':
      updatePeriod = SyndicationUpdatePeriod.monthly;
    case 'yearly':
      updatePeriod = SyndicationUpdatePeriod.yearly;
    default:
      updatePeriod = SyndicationUpdatePeriod.daily;
      break;
  }
  return Syndication(
    updatePeriod: updatePeriod,
    updateFrequency: int.tryParse(
      element.findElements('sy:updateFrequency').firstOrNull?.innerText ??
          '1',
    ),
    updateBase: parseDateTime(
      element.findElements('sy:updateBase').firstOrNull?.innerText,
    ),
  );
}