Class: Fed::Feed::Rss2

Inherits:
Base
  • Object
show all
Defined in:
lib/fed/feed/rss2.rb

Instance Attribute Summary

Attributes inherited from Base

#description, #document, #entries, #guid, #link, #title, #updated

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Fed::Feed::Base

Instance Method Details

#parseObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fed/feed/rss2.rb', line 4

def parse
  channel = @document.css('rss channel').first

  @title = channel.css('/title').text
  @description = channel.css('/description').text
  @link = channel.css('/link').text
  @updated = DateTime.parse(channel.css('/pubDate').text) rescue nil

  @entries = channel.css('item').map do |item|
    item_title = item.css('/title').text
    item_summary = item.css('/description').text
    item_content = item.css('/description').text
    item_link = item.css('/link').text
    item_published = DateTime.parse(item.css('/pubDate').text) rescue nil
    item_guid = item.css('/guid').text
    item_author = item.css('/author').text
    
    enclosure_elem = item.css('/enclosure').first
    item_enclosure = if !enclosure_elem.nil?
      url = enclosure_elem.attributes['url'] ? enclosure_elem.attributes['url'].value : ''
      content_type = enclosure_elem.attributes['type'] ? enclosure_elem.attributes['type'].value : ''
      Enclosure.new(url, content_type)
    else
      nil
    end

    Entry.new(item_title, item_link, item_guid, item_published, item_author, item_summary, item_content, item_enclosure)
  end

  self
end