Class: Urss::Feed::Atom::Entry

Inherits:
Entry
  • Object
show all
Defined in:
lib/urss/feed/atom_entry.rb

Instance Attribute Summary

Attributes inherited from Entry

#author, #categories, #comments_url, #content, #created_at, #medias, #title, #url

Class Method Summary collapse

Methods inherited from Entry

#initialize

Constructor Details

This class inherits a constructor from Urss::Feed::Entry

Class Method Details

.build(nokogiri_instance, namespace = nil) ⇒ Object

~~~~ Class methods ~~~~



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/urss/feed/atom_entry.rb', line 6

def self.build(nokogiri_instance, namespace=nil)
  raise Urss::NotANokogiriInstance unless nokogiri_instance.is_a?(Nokogiri::XML::Element)

  entry = self.new
  entry.title = nokogiri_instance.xpath("./#{namespace}title").text
  entry.url = nokogiri_instance.xpath("./#{namespace}link[@rel='alternate']").attr("href").value
  entry.created_at = nokogiri_instance.xpath("./#{namespace}published").text
  entry.author = nokogiri_instance.xpath("./#{namespace}author/#{namespace}name").text
  entry.content = case nokogiri_instance.xpath("./#{namespace}content").attr("type").value
  when "xhtml", "html"
    nokogiri_instance.xpath("./#{namespace}content").inner_html
  else
    nokogiri_instance.xpath("./#{namespace}content").text
  end

  unless (media = nokogiri_instance.xpath("./#{namespace}link[@rel='enclosure']")).empty?
    if media_url = media.attr("href").value
      entry.medias << Urss::Media.new(:content_url => media_url)
    end
  end

  entry
end