From: Kouhei Sutou Date: 2008-04-06T11:32:14+09:00 Subject: Re: Atom & the Standard Library RSS Module Hi, In <8311b2d9-35ea-4ff9-a294-8872eb52dbfa@c65g2000hsa.googlegroups.com> "Re: Atom & the Standard Library RSS Module" on Sat, 5 Apr 2008 20:45:06 +0900, grant wrote: > On 5 Apr, 01:29, Kouhei Sutou wrote: > > Please show an example. > > Sorry, I got tangled up in my own wishes. My problem with the library > was just in my head. I suppose I was just hoping for a more consistent > representation of a feed than I've had to deal with in the past. I > know that what is generated by RSS/ATOM parsing libraries is a > reflection of the feeds themselves. > > Anyway, a few examples of what bugs me, demonstrated in irb: > > require 'rss' > > rss = 'http://www.giftedslacker.com/feed/' > atom = 'http://oblivionation.blogspot.com/feeds/posts/default' > > rssfeed = RSS::Parser.parse(rss) > atomfeed = RSS::Parser.parse(atom) > You can normalize parsed feed by to_rss, to_atom or to_xml. For example: rss10feed = atomfeed.to_rss("1.0") You may need to set default value: rss10feed = atomfeed.to_rss("1.0") do |maker| maker.channel.about ||= maker.channel.link maker.channel.description ||= "No description" maker.items.each do |item| item.title ||= "UNKNOWN" item.link ||= "UNKNOWN" end end > #print the content of the most recent post > puts rssfeed.items[0].content_encoded > puts atomfeed.items[0].content.content > > #print the titles of the posts in the feed > rssfeed.items.each {|item| puts item.title} > atomfeed.items.each {|item| puts item.title.content} > > #print the author of the most recent post > rssfeed.items[0].dc_creator > atomfeed.entries[0].author.name.content The atom specification says that all atom element may have xml:base and xml:lang attributes. If RSS::Atom::Entry::Author#name returns a String, we can't get such attribute values. This is why RSS::Atom::Entry::Author#name returns an RSS::Atom::Entry::Author::Name not a String. BTW, what about the following API? atomfeed.entries[0].author.name # => a String atomfeed.entries[0].author.name do |name| # name: a RSS::Atom::Entry::Author::Name name.content # => a String end # => the last evaluated value (name.content) Thanks, -- kou