Class: Predicates::UsaZipCode
- Defined in:
- lib/predicates/usa_zip_code.rb
Overview
A United States zip code. Only validates format, does not attempt any verification for actual zip codes. Validates via regular expression.
Options
-
:extended [:allowed, :required, or false (default)] - whether to allow (or require!) the extended (+4) zip code format
Instance Attribute Summary collapse
-
#extended ⇒ Object
Returns the value of attribute extended.
Attributes inherited from Base
#full_message, #or_empty, #validate_if, #validate_on
Instance Method Summary collapse
Methods inherited from Pattern
Methods inherited from Base
#allow_empty?, #error, #error_binds, #initialize, #normalize, #to_human, #validate
Constructor Details
This class inherits a constructor from Predicates::Base
Instance Attribute Details
#extended ⇒ Object
Returns the value of attribute extended.
8 9 10 |
# File 'lib/predicates/usa_zip_code.rb', line 8 def extended @extended end |
Instance Method Details
#error_message ⇒ Object
22 23 24 |
# File 'lib/predicates/usa_zip_code.rb', line 22 def @error_message || :us_zip_code end |
#like ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/predicates/usa_zip_code.rb', line 10 def like return @like unless @like.nil? pattern = '[0-9]{5}' if extended pattern += '(-[0-9]{4})' pattern += '?' unless extended == :required end @like = /\A#{pattern}\Z/ end |