Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case_sensitive parameter to Choice.__init__ #12

Open
todofixthis opened this issue Jan 17, 2017 · 0 comments
Open

Add case_sensitive parameter to Choice.__init__ #12

todofixthis opened this issue Jan 17, 2017 · 0 comments

Comments

@todofixthis
Copy link
Contributor

todofixthis commented Jan 17, 2017

Allow Choice to ignore case by passing an optional parameter to its __init__ method.

When applied, the filter should return the matching choice (i.e., automatically "fix" case mismatch).

Example:

>>> Choice(choices={'MOE', 'LARRY', 'CURLY', 'SHEMP'}, case_sensitive=False)\
...   .apply('Moe')
MOE # (changed to UPPERCASE to match valid choice)

Note that this yields a different result than using case folding:

>>> (CaseFold | Choice(choices={'MOE', 'LARRY', 'CURLY', 'SHEMP'}))\
...   .apply('Moe')
# Input is case-folded before Choice filter sees it, so it doesn't match anything.
FilterError: Valid options are: ['CURLY', 'LARRY', 'MOE', 'SHEMP']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant