Class: BirdFeed::Atom10

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Format

detect, register, registered_formats

Constructor Details

#initialize(xml) ⇒ Atom10

Returns a new instance of Atom10.



7
8
9
10
# File 'lib/birdfeed/format/atom10.rb', line 7

def initialize(xml)
  @xml = xml
  @doc = Nokogiri::XML(xml)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/birdfeed/format/atom10.rb', line 5

def doc
  @doc
end

#xmlObject (readonly)

Returns the value of attribute xml.



5
6
7
# File 'lib/birdfeed/format/atom10.rb', line 5

def xml
  @xml
end

Class Method Details

.formatObject



13
14
15
# File 'lib/birdfeed/format/atom10.rb', line 13

def format
  "Atom 1.0"
end

.parse(content) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/birdfeed/format/atom10.rb', line 17

def parse(content)
  Nokogiri::parse(content) do |xml|
    return Feed.new(self) do |feed|
      feed.raw_content = content
      feed.title = xml.css('feed > title').text
      feed.description = xml.css('feed > subtitle').text
      feed.link = xml.css('feed > link').first.get_attribute('href')
      feed.updated_at = xml.css('feed > updated').text
      xml.css('feed > entry').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('content').text
          item.link = item_node.css('link').attr('href')
          item.id = item_node.css('id').text
          item.author = item_node.css('author > name').text
        end
      end
    end
  end
end

.valid?(xml) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/birdfeed/format/atom10.rb', line 40

def valid?(xml)
  not Nokogiri::parse(xml).search('feed[xmlns="http://www.w3.org/2005/Atom"]').empty?
end