Class: Fed::Feed::Atom

Inherits:
Base
  • Object
show all
Defined in:
lib/fed/feed/atom.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
35
36
37
38
39
40
# File 'lib/fed/feed/atom.rb', line 4

def parse
  feed = @document.css('feed').first

  @title = feed.css('/title').text
  @description = feed.css('/subtitle').text
  @link = feed.css('/link').first.attributes['href'].value
  @updated = DateTime.parse(feed.css('/updated').text) rescue nil

  @entries = feed.css('entry').map do |entry|
    entry_title = entry.css('/title').text
    entry_summary = entry.css('/summary').text
    entry_content = entry.css('/content').text
     = DateTime.parse(entry.css('/updated').text) rescue nil
    entry_guid = entry.css('/id').text
     = entry.css('/author name').map {|a| a.text}.join(', ')

    link_elem = entry.css("link[rel='alternate']").first
    entry_link = if (link_elem && (attribute = link_elem.attributes['href']))
      attribute.value
    else
      ""
    end

    enclosure_elem = entry.css("link[rel='enclosure']").first
    entry_enclosure = if !enclosure_elem.nil?
      url = enclosure_elem.attributes['href'] ? enclosure_elem.attributes['href'].value : ''
      content_type = enclosure_elem.attributes['type'] ? enclosure_elem.attributes['type'].value : ''
      Enclosure.new(url, content_type)
    else
      nil
    end

    Entry.new(entry_title, entry_link, entry_guid, , , entry_summary, entry_content, entry_enclosure)
  end

  self
end