Sha256: 8e3eecad782814e26d691da32412f00531c94de94b350edb7cbfbb7d58110aaf

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 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

          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_published, entry_author, entry_summary, entry_content, entry_enclosure)
        end

        self
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fed-0.0.5 lib/fed/feed/atom.rb