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:
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