Sha256: 8d6a916283739757e39d8954cfa5a7507f62b66a0c5cf1be354862687f73c8a3

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Fed
  module Feed
    class Atom < Base
      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
          entry_published = DateTime.parse(entry.css('/updated').text) rescue nil
          entry_guid = entry.css('/id').text
          entry_author = 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

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

        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fed-0.0.2 lib/fed/feed/atom.rb
fed-0.0.1 lib/fed/feed/atom.rb