Velocity Reviews > Ruby > [ANN] Joker -- Wildcards for Ruby

# [ANN] Joker -- Wildcards for Ruby

Fabian Streitel
Guest
Posts: n/a

 09-09-2009
[Note: parts of this message were removed to make it a legal post.]

Hi folks,
I'm proudly presenting:

# Joker #

http://karottenreibe.github.com/joker

Joker is a Wildcard implementation for Ruby.

## Features ##

* Behaves much like Regexp
*  *  and  ?  as wildcard characters
*  \  for escaping
* \a matches \a, but not a
* Wildcards must always match whole string
* Wildcards can be case insensitive

Visit the website to see a small example etc.

Greetz!

James Edward Gray II
Guest
Posts: n/a

 09-09-2009
On Sep 9, 2009, at 12:55 PM, Fabian Streitel wrote:

> I'm proudly presenting:
>
> # Joker #
>
> http://karottenreibe.github.com/joker
>
> Joker is a Wildcard implementation for Ruby.
>
> ## Features ##
>
> * Behaves much like Regexp
> *  *  and  ?  as wildcard characters
> *  \  for escaping
> * \a matches \a, but not a
> * Wildcards must always match whole string
> * Wildcards can be case insensitive

Can you suggest why someone would use this instead of a regular
expression?

James Edward Gray II

Fabian Streitel
Guest
Posts: n/a

 09-09-2009
[Note: parts of this message were removed to make it a legal post.]

because "non-computer people" ( might find wildcards more easily
understandable than regular expressions.

This is of course not meant as a replacement for regexps when you're
writing code but rather as a way to interface with people who don't

think directory listings, search queries etc.

Greetz!

2009/9/9 James Edward Gray II <(E-Mail Removed)>

> On Sep 9, 2009, at 12:55 PM, Fabian Streitel wrote:
>
>
> Can you suggest why someone would use this instead of a regular expression?
>
> James Edward Gray II
>
>
>

Fabian Streitel
Guest
Posts: n/a

 09-10-2009
[Note: parts of this message were removed to make it a legal post.]

> Note that these are known as "glob patterns" -- you might want to update
>

Ah, thx, I've been searching for the correct name of these but couldn't find
it.
The only thing I've ever heard was "Wildcard".

>
> Also, your rdocs seem to be missing a few backslashes:
>
> * '?' matches a single character
> * '*' matches any number of characters, including 0
> (1) * '*' matches a literal '*'
> * '\?' matches a literal '?'
> (2) * '\' matches a literal '\'
>
> 1 should be: '\*' matches a literal '*'
> 2 should be: '\\' matches a literal '\'
>
> You could generalize by saying:
> * '\x' matches the literal character 'x', even if 'x' is a wildcard
> character.
>

I'll do that.

>
> You haven't implemented bracket expressions: '[cb]at*' should match
> 'catch' and 'batch' but not 'match'
>

I'll look into that.

Thanks for the feedback!

Fabian Streitel
Guest
Posts: n/a

 09-10-2009
[Note: parts of this message were removed to make it a legal post.]

Whoops overlooked one:

You could generalize by saying:
> * '\x' matches the literal character 'x', even if 'x' is a wildcard
> character.
>
>

That's exactly not what my implementation does. Since I had the library in
mind as
a way to interact with users who don't know about Regular Expressions, I
wanted
to keep it as simple as possible.

Thus, the Ruby String "fo\\o" fed to the Wildcard class would be equivalent
to /^fo\\o\$/
but I'm not sure if that was a wise decision. The reasoning behind it was,
that users woudn't
have to type things like
C:\\foo\\bar\\goo
but rather only
C:\foo\bar\goo
since f b and g are no special characters.

Does that make sense? What do you think? Which approach to take or should
there be an option
and if so what's the wiser default?
Greetz!

Joel VanderWerf
Guest
Posts: n/a

 09-10-2009

Just a thought... ruby already has globbing functions in dir.c, but they
apparently work only on dirs. Maybe they could be abstracted in to a
library that works on strings or arrays of strings.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Fabian Streitel
Guest
Posts: n/a

 09-11-2009
[Note: parts of this message were removed to make it a legal post.]

>
> Just a thought... ruby already has globbing functions in dir.c, but they
> apparently work only on dirs. Maybe they could be abstracted in to a library
> that works on strings or arrays of strings.
>
>

Honestly: I have no idea what's going on in that file...
That's just too complicated C magic whuzzing around in there.

But a problem with that approach -- as far as I can tell -- is that
matching a glob against a string and matching it against the
file system are 2 different things. Especially since "/" or "\" have
special meaning in file systems and allow for splitting of the glob
string into small subsections, whose matching against files is much
easier.
Also dir.c has the special "**" glob, which doesn't make and sense
in string matching.

Greetz!