On 25 Mar 2013, at 17:41, Konstantin Haase wrote:
> Quick survey,
>
> 1. How would you expect `get '/:id(.format)?'` to match "/foo.bar"? Valid responses: {id:'foo', format:'bar'} or {id:'foo.bar', fromat:nil}.
{id: 'foo.bar', format: nil}
Never ever {id: 'foo', format: 'bar'}
> 2. How would you expect `get '/:id.:format` to parse "/hello.world.html"?
I'd expect it to follow regex rules, which takes the greediest possible match:
{id: "hello.world", format: "html"}
e.g
s =
r = /\/(?<id>.+)\.(?<format>.+)/
r.match s
# => #<MatchData "/hello.world.html" id:"hello.world" format:"html">
and
File.extname s
# => ".html"
File.basename s, File.extname(s)
# => "hello.world"
> 2. How would you expect `get '/:id.:format` to parse "/download.tar.gz"?
Um, 2? :P :)
Same again:
s = "/download.tar.gz"
r = /\/(?<id>.+)\.(?<format>.+)/
r.match s
# => #<MatchData "/download.tar.gz" id:"download.tar" format:"gz">
It's a gzipped tarball, so technically it's .gz. The tarball is the resource, not the contents of the tarball. `tar` recognises gzip compression as a convenience so you can *pass around the tarball*. That's how I'd think of it.
> 3. How would you expect `get '/:id.:format` to parse "/a.brief.blog.post.html"?
Without the regex, as I'm sounding like a computer now…
{ id: "
a.brief.blog.post" format: "html" }
but that is how the regex would match it :)
Regards,
Iain
>
> Feel free to add justifications and comments.
>
> Thank you for your time.
>
> Konstantin
>