From: Nicholas Van Weerdenburg Date: 2005-01-22T05:42:56+09:00 Subject: Re: Xpath like syntax I'd like a simple addition to Enumerable. Also, maybe combine the concepts of XPath and XQuery. nodes= aobjectgraph.traverse("graph path here") # or nodes= aobjectgraph.query( "query spec here") As well as the block result processing versions. I think following the semantics of xpath and xquery, while maintaining the semantics of Enumerable, would be ideal. In that light, filters and such would ideally be done via normal Enumerable primitives. To follow Ruby conventions, it may make more sense to extend find/select or add a graph_select/graph_find method (maintaining similarity to select/find naming). Regards, Nick On Sat, 22 Jan 2005 04:50:05 +0900, Aredridel wrote: > On Sat, 22 Jan 2005 04:25:57 +0900, trans. wrote: > > Traversable mixin! That would be great! > > Would a single method, traverse_component be sufficient to build an > implementation on, do you think? Pass it a path component, and have the > object return whatever makes sense? (for a hash or array, map it to []; > for Objects in general, map it to send?) > > Perhaps have a second method, traverse_filter, that receives an array of > filters, for XPath-style qualifications like [@attr = 'foo'], or > [/childobject]? > > > As for API, probably best just would work out what your current needs > > are (I assume you have a current need ;-), and implement that first. > > Most of the rest wil probbly fall out from there, and then others can > > offer additional suggestion for functionaity. That's how I'd probbly > go > > about it, anyway. > > My uses are, right now, for passing an object graph as model data to an > XTemplate view (something that Amrita does, and XTemplate does not, > yet), and for mapping a rails-style URL to an object graph of handlers > -- so that /foo/bar/baz maps to (roughly) startingpoint.foo.bar.baz > > > Keep me informed and I'd be glad to help in any way I can. > > Alright. > > Ari > > ---- > Ruby web hosting? http://theinternetco.net/offers/ruby > ``> -- Nicholas Van Weerdenburg