One of the big advantages that Mark Pilgrim’s UFP has over FeedTools is in its *_detail methods. The UFP basically gives you a bunch more information without having to dive into XPath or some such. In a couple of obvious places, like the author field, FeedTools also does this, but it used to do it with an interesting trick.
I really didn’t like the idea of having two different methods to retrieve what was essentially the same piece of information. But I also didn’t like forcing people who were used to element names from RSS being stuck using a more unfamiliar Atom-like class structure.
So awhile back, I made it so that there were these special funky classes, like the FeedTools::Author class, that were basically a structure containing the author’s name, email, url, and the raw data in the case of an RSS feed. So you could write:
1
2
3
4
5
6
7
8
9
|
feed = FeedTools::Feed.open(
'http://sporkmonger.com/xml/atom10/feed.xml')
feed.author.name
=> 'Bob Aman'
feed.author.email
=> 'bob@sporkmonger.com'
feed.author.url
=> 'http://sporkmonger.com/'
|
But… you could also write:
1
2
3
4
5
|
feed = FeedTools::Feed.open(
'http://sporkmonger.com/xml/atom10/feed.xml')
feed.author
=> 'Bob Aman'
|
Because I had used method_missing to relay any missing methods on the class to the name object, and overwritten the inspect method and a few others to do the same.
I eventually removed it because the code was quite repetitive (though I know how to fix that at this point), but also because I was worried that someone might actually need one of those overwritten methods for some reason, and also because I thought ‘chameleon classes’ might be surprising to some people. Actually, quite possibly very surprising. And you know, we supposedly want ‘least surprise.’
Now, the reason I’m bringing this up is because I wanted to get more information attached to the content element. I could change the API and have the content method return a class instead of a string, I could leave it the way it is and go with the Mark Pilgrim method, or I could return to the ‘chameleon classes’ only better written the second time round.
My personal preference is actually the shape changing niftiness, despite my reservations. Aesthetically, I think it’s the nicest looking solution, because it keeps the API much, much closer to the names of the elements in the respective syndication formats. Remember, our fearless leaders are of the opinion that beauty and productivity go hand in hand. But I worry, so I’m just going to ask you guys, what do you prefer, and why?
Oh yeah, and I’m strongly considering following Mark’s example and using ‘href’ everywhere for consistency.