Class: BirdFeed::Rss20

Inherits:
Format
  • Object
show all
Defined in:
lib/birdfeed/format/rss20.rb

Class Method Summary collapse

Methods inherited from Format

detect, register, registered_formats

Class Method Details

.formatObject



6
7
8
# File 'lib/birdfeed/format/rss20.rb', line 6

def format
  "RSS 2.0"
end

.parse(content) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/birdfeed/format/rss20.rb', line 10

def parse(content)
  Nokogiri::parse(content) do |xml|
    return Feed.new(self) do |feed|
      feed.raw_content = content
      feed.title = xml.css('rss > channel > title').text
      feed.description = xml.css('rss > channel > description').text
      feed.link = xml.css('rss > channel > link').text
      feed.updated_at = xml.css('rss > channel > pubDate').text
      xml.css('rss > channel item').each do |item_node|
        feed.items << Item.new do |item|
          item.xml = item_node.to_xml
          item.node = item_node
          item.title = item_node.css('title').text
          item.description = item_node.css('description').text
          item.link = item_node.css('link').text
          item.id = item_node.css('guid').text
        end
      end
    end
  end
end

.valid?(content) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/birdfeed/format/rss20.rb', line 32

def valid?(content)
  not Nokogiri::parse(content).css('rss[version="2.0"]').empty?
end