From: Sam Roberts Date: 2003-03-16T05:05:34+09:00 Subject: Re: ANN: vcard 0.1 - a vCard decoding library Quoteing rich@infoether.com, on Sun, Mar 16, 2003 at 04:15:57AM +0900: > One quick recommendation is to use the index method [] as an alias for > value_of on the VCard object...that way you could do this: > > VCDATA =< BEGIN:VCARD > VERSION:3.0 > N:Kilmer;Rich;;; > FN:Kilmer Rich > EMAIL;type=HOME:rich@monotheos.com > EMAIL;type=WORK;type=pref:rich@infoether.com > END:VCARD > END > > card = Rfc2425::VCard.new(VCDATA) > puts card["email"] #=> rich@infoether.com I thought about it, but didn't because I ran into the "which one do I return, there can be multiple fields with that name" problem. I just looked at RFC2426 in more detail, though, and it appears that type=pref is allowed for a lot of things that can have multiple occurences. > and possibly accept symbols in addition to strings: > > puts card[:email] #=> rich@infoether.com > > and perhaps enable a second (optional) param for the type: > > puts card[:email, :home] #=> rich@monotheos.com > > class VCard > def [](fieldname, ftype=nil) > ... > end > end And if there are multiple matches, you'll always get the first, unless one of them is pref?(), ok? Cheers, Sam