Class: Urss::Feed::Rss

Inherits:
Urss::Feed show all
Defined in:
lib/urss/feed/rss.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary

Attributes inherited from Urss::Feed

#description, #entries, #title, #updated_at, #url

Class Method Summary collapse

Methods inherited from Urss::Feed

#initialize

Constructor Details

This class inherits a constructor from Urss::Feed

Class Method Details

.build(nokogiri_instance, namespace, root_node) ⇒ Object

~~~~ Class methods ~~~~



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

def self.build(nokogiri_instance, namespace, root_node)
  raise Urss::NotANokogiriInstance unless nokogiri_instance.is_a?(Nokogiri::XML::NodeSet)
  feed_rss = self.new
  feed_rss.title = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}title").text
  feed_rss.url = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}link").text
  feed_rss.description = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}description").text
  feed_rss.updated_at = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}pubDate").text
  if feed_rss.updated_at.nil? || feed_rss.updated_at.empty?
    begin
      feed_rss.updated_at = nokogiri_instance.xpath("//#{namespace}#{root_node}/dc:date").text
    rescue Nokogiri::XML::XPath::SyntaxError
      # No pubDate or date field
    end
  end
  nokogiri_instance.xpath("//#{namespace}item").each {|item| feed_rss.entries << Urss::Feed::Rss::Entry.build(item, namespace)}

  feed_rss
end