case insensitivity for attributes?

12 views
Skip to first unread message

atduskgreg

unread,
Jan 23, 2008, 4:57:40 PM1/23/08
to mofo
Hey Y'all,

Just sitting down to add the ability to parse hAtom to mofo [http://
microformats.org/wiki/haudio] and ran into a prominent example that
follows the spec correctly but happens to use capitalized versions of
some of the class names [http://openmediaweb.org/index.php/2008/01/13/
publishing-my-workout-music-in-haudio/] (specifically "Album" rather
than "album").

Strictly speaking, the spec would probably consider these invalid for
that reason, but the internet really just being a bunch of typing, I
bet this kind of thing happens all the time and so was wondering if
there was we could make attributes case insensitive, i.e. calling
one :album in your Microformat sub-class would find elements with
class "album" as well as class "Album".

I looked a bit into figuring out what would be necessary for this but
the dark black magic heart of microformat.rb makes me think this might
be an easy change for someone with more familiarity with it to make
with more confidence than I would as lowly visitor.

Thanks! And thanks for this great lib. I should have a patch to submit
with hAudio support soon!

yours,

Greg
---
http://grabb.it/users/greg
http://urbanhonking.com/ideasfordozens
http://atduskmusic.com

Chris Wanstrath

unread,
Jan 23, 2008, 5:39:31 PM1/23/08
to mof...@googlegroups.com
On 1/23/08, atduskgreg <greg.bo...@gmail.com> wrote:

> Strictly speaking, the spec would probably consider these invalid for
> that reason, but the internet really just being a bunch of typing, I
> bet this kind of thing happens all the time and so was wondering if
> there was we could make attributes case insensitive, i.e. calling
> one :album in your Microformat sub-class would find elements with
> class "album" as well as class "Album".

Great question, and idea. This is sorta an Hpricot issue -- we need
to find a way to make Hpricot searches case insensitive.

Observe the current, case sensitive behavior:

>> require 'hpricot'
=> true
>> require 'open-uri'
=> true
>> url = 'http://openmediaweb.org/index.php/2008/01/13/publishing-my-workout-music-in-haudio/'
=> "http://openmediaweb.org/index.php/2008/01/13/publishing-my-workout-music-in-haudio/"
>> doc = Hpricot open(url)
=> #<Hpricot::Doc {doctype BUNCH OF CRAP}>
>> doc/'.album'
=> #<Hpricot::Elements[]>
>> doc/'.Album'
=> #<Hpricot::Elements[{elem BUNCH OF CRAP}]>

The issue is brought up in the Hpricot FAQ:
http://code.whytheluckystiff.net/hpricot/wiki/HpricotChallenge#IgnoringCase

Maybe we can use one of those solutions? Anyone Hpricot users have an
opinion? I definitely agree with you -- Album and album should both
be valid. The spec be damned!

> I looked a bit into figuring out what would be necessary for this but
> the dark black magic heart of microformat.rb makes me think this might
> be an easy change for someone with more familiarity with it to make
> with more confidence than I would as lowly visitor.

It is the blackest of magic hearts. The result of sleeping too little
and dreaming too big.

--
Chris Wanstrath
http://errfree.com // http://errtheblog.com
http://github.com // http://famspam.com

Greg Borenstein

unread,
Jan 23, 2008, 6:09:29 PM1/23/08
to mof...@googlegroups.com
How about this?

doc/"[@class=Album]|[@class=album]"

This being code by _why, of course the pipe works.

Again, I'm swinging blind through the cloud of black magic here, but
it seems to me like making microformat.rb205 into:

capitalized_key = key.no_bang.to_s.gsub('_','-').capitalize
found = doc/"[@class=#{capitalized_key}]|
[@class=#{capitalized_key.downcase}]"

might do the trick.

Whaddya think?

-- Greg

Chris Wanstrath

unread,
Jan 23, 2008, 6:16:32 PM1/23/08
to mof...@googlegroups.com
On 1/23/08, Greg Borenstein <greg.bo...@gmail.com> wrote:

> How about this?
>
> doc/"[@class=Album]|[@class=album]"

What about class="ALBUM" ? :)

- Chris

Greg Borenstein

unread,
Jan 23, 2008, 7:15:26 PM1/23/08
to mof...@googlegroups.com
Ah, touché.

After digging around a bit in the hpricot internals, I'm convinced
there's some way to do this by over-riding some regexp-related methods
on the string you pass in to doc/ or doc.search, but I haven't quite
got it yet (if you think your code has a dark heart...I mean jeez!).

-- Greg

Reply all
Reply to author
Forward
0 new messages