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

Have valid? method to test for valid inputs rather than raising exceptions. #14

Open
wakproductions opened this issue Nov 3, 2013 · 0 comments

Comments

@wakproductions
Copy link

Hi Jonathan! What a terrific and useful gem you have here! Nice work.

May I suggest that you implement a way to handle invalid data aside from raising an exception? For use cases involving user-generated input, it may be necessary to have some sort of validation test. Creating a rescue block for every usage makes for some unsightly code. It would be nice to be able to do something like:

postal_code="SE151AA" # a UK postal code
if postal_code.valid_zip_code?

do one thing

else
#do invalid zip code handling
end

Another problem with the way errors are currently handled is that you can pass it an invalid code and in some circumstances it will return nil. This inconsistency makes error handling more difficult:

"ABCDE".to_region
=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant