Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Last active March 9, 2017 02:40
Show Gist options
  • Save jgaskins/72cfc3960339579c0b0f40f5d09be14c to your computer and use it in GitHub Desktop.
Save jgaskins/72cfc3960339579c0b0f40f5d09be14c to your computer and use it in GitHub Desktop.
Parse a Podcast feed into episodes
class Episode
def self.from_rss_feed(url)
xml = Nokogiri.parse(Net::HTTP.get(URI(url)))
xml.xpath('//channel/item').map do |item|
new(
title: item.at_xpath('title').text,
subtitle: item.at_xpath('itunes:subtitle').text,
link: item.at_xpath('link').text,
audio_url: item.at_xpath('enclosure')[:url],
duration: item.at_xpath('itunes:duration').text
)
end
end
def initialize(title:, subtitle:, link:, audio_url:, duration:)
@title = title
@subtitle = subtitle
@link = link
@audio_url = audio_url
@duration = duration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment