Class: Predicates::UsaState
- Inherits:
-
Aliased
- Object
- Base
- Enumerated
- Aliased
- Predicates::UsaState
- Defined in:
- lib/predicates/usa_state.rb
Overview
Requires that an attribute be in a list of valid USA states. Machine format is the abbreviation, human format is the whole word. List acquired from: www.usps.com/ncsc/lookups/abbr_state.txt
Options
-
:with_territories [boolean, default false] - whether to allow territories
Constant Summary collapse
- TERRITORIES =
{ 'American Samoa' => 'AS', 'Federated States of Micronesia' => 'FM', 'Guam' => 'GU', 'Marshall Islands' => 'MH', 'Northern Mariana Islands' => 'MP', 'Palau' => 'PW', 'Puerto Rico' => 'PR', 'Virgin Islands' => 'VI' }
- STATES =
{ 'Alabama' => 'AL', 'Alaska' => 'AK', 'Arizona' => 'AZ', 'Arkansas' => 'AR', 'California' => 'CA', 'Colorado' => 'CO', 'Connecticut' => 'CT', 'Delaware' => 'DE', 'District of Columbia' => 'DC', 'Florida' => 'FL', 'Georgia' => 'GA', 'Hawaii' => 'HI', 'Idaho' => 'ID', 'Illinois' => 'IL', 'Indiana' => 'IN', 'Iowa' => 'IA', 'Kansas' => 'KS', 'Kentucky' => 'KY', 'Louisiana' => 'LA', 'Maine' => 'ME', 'Maryland' => 'MD', 'Massachusetts' => 'MA', 'Michigan' => 'MI', 'Minnesota' => 'MN', 'Mississippi' => 'MS', 'Missouri' => 'MO', 'Montana' => 'MT', 'Nebraska' => 'NE', 'Nevaga' => 'NV', 'New Hampshire' => 'NH', 'New Jersey' => 'NJ', 'New Mexico' => 'NM', 'New York' => 'NY', 'North Carolina' => 'NC', 'North Dakota' => 'ND', 'Ohio' => 'OH', 'Oklahoma' => 'OK', 'Oregon' => 'OR', 'Pennsylvania' => 'PA', 'Rhode Island' => 'RI', 'South Carolina' => 'SC', 'South Dakota' => 'SD', 'Tennessee' => 'TN', 'Texas' => 'TX', 'Utah' => 'UT', 'Vermont' => 'VT', 'Virginia' => 'VA', 'Washington' => 'WA', 'West Virginia' => 'WV', 'Wisconsin' => 'WI', 'Wyoming' => 'WY' }
Instance Attribute Summary collapse
-
#with_territories ⇒ Object
writeonly
a boolean for whether to allow united states territories.
Attributes inherited from Base
#full_message, #or_empty, #validate_if, #validate_on
Instance Method Summary collapse
Methods inherited from Aliased
#normalize, #to_human, #validate
Methods inherited from Enumerated
Methods inherited from Base
#allow_empty?, #error, #error_binds, #initialize, #normalize, #to_human, #validate
Constructor Details
This class inherits a constructor from Predicates::Enumerated
Instance Attribute Details
#with_territories=(value) ⇒ Object (writeonly)
a boolean for whether to allow united states territories. default is false.
9 10 11 |
# File 'lib/predicates/usa_state.rb', line 9 def with_territories=(value) @with_territories = value end |
Instance Method Details
#error_message ⇒ Object
19 20 21 |
# File 'lib/predicates/usa_state.rb', line 19 def @error_message || with_territories? ? :us_state_or_territory : :us_state end |
#options ⇒ Object
14 15 16 |
# File 'lib/predicates/usa_state.rb', line 14 def @options ||= STATES.merge(with_territories? ? TERRITORIES : {}) end |
#with_territories? ⇒ Boolean
10 11 12 |
# File 'lib/predicates/usa_state.rb', line 10 def with_territories? @with_territories ? true : false end |