Class: MTP::Podcast::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/mtp/podcast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, options = {}) ⇒ Feed

Returns a new instance of Feed.



28
29
30
31
32
# File 'lib/mtp/podcast.rb', line 28

def initialize(title, options = {})
  @title = title
  @url = options["url"] || options[:url]
  @keep = options["keep"] || options[:keep]
end

Instance Attribute Details

#keepObject

Returns the value of attribute keep.



27
28
29
# File 'lib/mtp/podcast.rb', line 27

def keep
  @keep
end

#titleObject

Returns the value of attribute title.



27
28
29
# File 'lib/mtp/podcast.rb', line 27

def title
  @title
end

#urlObject

Returns the value of attribute url.



27
28
29
# File 'lib/mtp/podcast.rb', line 27

def url
  @url
end

Instance Method Details

#itemsObject



34
35
36
37
38
39
40
# File 'lib/mtp/podcast.rb', line 34

def items
  content = nil
  open(@url) { |s| content = s.read }
  parser = Syndication::RSS::Parser.new
  rss = parser.parse(content)
  rss.items.select { |i| i.keep = @keep; i.pubdate.to_time > @keep.days.ago }
end