//
//  RSSFeed+Extensions.swift
//  Search
//
//  Created by Eugene Karambirov on 26/09/2018.
//  Copyright © 2018 Eugene Karambirov. All rights reserved.
//

import FeedKit

extension RSSFeed {

  func toEpisodes() -> [Episode] {
    let imageUrl = iTunes?.iTunesImage?.attributes?.href

    var episodes = [Episode]()
    items?.forEach { feedItem in
      var episode = Episode(feedItem: feedItem)

      if episode.imageUrl == nil {
        episode.imageUrl = imageUrl
      }

      episodes.append(episode)
    }

    return episodes
  }

}