validatious 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  Validatious -- A collection of delicious Rails validators
2
2
  =========================================================
3
3
 
4
- ## DESCRIPTION
5
-
6
4
  No matter what app you are working on, Rails never seems to include all the
7
5
  validations you need, and you end having to repeat yourself over and over by
8
6
  writing regex validations and/or custom validators.
@@ -66,6 +64,26 @@ or
66
64
 
67
65
  validates_email_format_of :email
68
66
 
67
+
68
+ ### Postal Code
69
+
70
+ This validates the format of a postal code address, ensuring that the attribute conforms
71
+ to the correct format as specified by the given country (default: US).
72
+
73
+ validates :zip, :postal_code => true
74
+
75
+ or specify a different country
76
+
77
+ validates :zip, :postal_code => { :country => 'UK' }
78
+
79
+ or validate for several countries
80
+
81
+ validates :zip, :postal_code => { :country => [ 'US', 'CA' ] }
82
+
83
+ or
84
+
85
+ validates_postal_code_format_of :zip
86
+
69
87
 
70
88
  ### Text Content
71
89
 
data/lib/validatious.rb CHANGED
@@ -9,7 +9,13 @@ end
9
9
  require "validatious/validators/url_validator"
10
10
  require "validatious/validators/email_validator"
11
11
  require "validatious/validators/text_content_validator"
12
+ require "validatious/validators/postal_code_validator"
12
13
  require "validatious/helper_methods"
13
14
 
15
+ require "validatious/addresses/searchable"
16
+ require "validatious/addresses/states"
17
+ require "validatious/addresses/countries"
18
+ require "validatious/addresses/provinces"
19
+
14
20
  require 'active_support/i18n'
15
21
  I18n.load_path << File.dirname(__FILE__) + '/validatious/locale/en.yml'
@@ -0,0 +1,346 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Validatious
3
+ module Addresses
4
+ module Countries
5
+ include Searchable
6
+
7
+ postal5 = /^\d{5}$/
8
+ postal4 = /^\d{4}$/
9
+ postal6 = /^\d{6}$/
10
+
11
+ COUNTRIES = [
12
+ { :name => 'Austria', :numeric => '040', :alpha2 => 'AT', :alpha3 => 'AUT', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
13
+ { :name => 'Australia', :numeric => '036', :alpha2 => 'AU', :alpha3 => 'AUS', :continent => 'Australia', :region => ['Southern Hemisphere', 'Eastern Hemisphere', 'Australia'], :postal_code => postal4 },
14
+ { :name => 'Belgium', :numeric => '056', :alpha2 => 'BE', :alpha3 => 'BEL', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
15
+ { :name => 'Bulgaria', :numeric => '100', :alpha2 => 'BG', :alpha3 => 'BGR', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
16
+ { :name => 'Canada', :numeric => '124', :alpha2 => 'CA', :alpha3 => 'CAN', :continent => 'North America', :region => ['Northern Hemisphere', 'Western Hemisphere', 'North America'], :postal_code => /^([A-Z]\d[A-Z][\-\s]?\d[A-Z](\d)?)$/i },
17
+ { :name => 'Cyprus', :numeric => '196', :alpha2 => 'CY', :alpha3 => 'CYP', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
18
+ { :name => 'Czech Republic', :numeric => '203', :alpha2 => 'CZ', :alpha3 => 'CZE', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(CZ-)?\d{3}(\s)?\d{2}$/i },
19
+ { :name => 'Denmark', :numeric => '208', :alpha2 => 'DK', :alpha3 => 'DNK', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3,4}$/ },
20
+ { :name => 'Estonia', :numeric => '233', :alpha2 => 'EE', :alpha3 => 'EST', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(EE-)?\d{4,5}$/i },
21
+ { :name => 'Finland', :numeric => '246', :alpha2 => 'FI', :alpha3 => 'FIN', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
22
+ { :name => 'France', :numeric => '249', :alpha2 => 'FR', :alpha3 => 'FRA', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
23
+ { :name => 'Germany', :numeric => '278', :alpha2 => 'DE', :alpha3 => 'DEU', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
24
+ { :name => 'Greece', :numeric => '300', :alpha2 => 'GR', :alpha3 => 'GRC', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3}(\s)?\d{2}$/ },
25
+ { :name => 'Hungary', :numeric => '348', :alpha2 => 'HU', :alpha3 => 'HUN', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
26
+ { :name => 'Ireland', :numeric => '372', :alpha2 => 'IE', :alpha3 => 'IRL', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /.?/ },
27
+ { :name => 'Italy', :numeric => '380', :alpha2 => 'IT', :alpha3 => 'ITA', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
28
+ { :name => 'Latvia', :numeric => '428', :alpha2 => 'LV', :alpha3 => 'LVA', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /(LV-)?\d{4}^$/i },
29
+ { :name => 'Lithuania', :numeric => '440', :alpha2 => 'LT', :alpha3 => 'LTU', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(LT-)?\d{5}$/i },
30
+ { :name => 'Luxembourg', :numeric => '442', :alpha2 => 'LU', :alpha3 => 'LUX', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
31
+ { :name => 'Malta', :numeric => '470', :alpha2 => 'MT', :alpha3 => 'MLT', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^[A-Z]{3}(\s)?\d{4}$/i },
32
+ { :name => 'Netherlands', :numeric => '528', :alpha2 => 'NL', :alpha3 => 'NLD', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{4}(\s)?[A-Z]{2}(\s)?(\d*)?$/ },
33
+ { :name => 'Poland', :numeric => '616', :alpha2 => 'PL', :alpha3 => 'POL', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{2}[\-\s]?\d{3}$/ },
34
+ { :name => 'Portugal', :numeric => '620', :alpha2 => 'PT', :alpha3 => 'PRT', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{4}[\-\s]?\d{3}$/ },
35
+ { :name => 'Romania', :numeric => '642', :alpha2 => 'RO', :alpha3 => 'ROM', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{6}$/ },
36
+ { :name => 'Slovakia', :numeric => '703', :alpha2 => 'SK', :alpha3 => 'SVK', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(SK-)?\d{3}(\s)?\d{2}$/ },
37
+ { :name => 'Slovenia', :numeric => '705', :alpha2 => 'SI', :alpha3 => 'SVN', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(SL-)?\d{4}$/i },
38
+ { :name => 'Spain', :numeric => '724', :alpha2 => 'ES', :alpha3 => 'ESP', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
39
+ { :name => 'Sweden', :numeric => '752', :alpha2 => 'SE', :alpha3 => 'SWE', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3}(\s)?\d{2}$/ },
40
+ { :name => 'United Kingdom', :numeric => '826', :alpha2 => 'GB', :alpha3 => 'GBR', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^[\dA-Z]{2,4}(\s)?[\dA-Z]{3}$/i },
41
+ { :name => 'United States', :numeric => '840', :alpha2 => 'US', :alpha3 => 'USA', :continent => 'North America', :region => ['Northern Hemisphere', 'Western Hemisphere', 'North America'], :postal_code => /^\d{5}([\-\s]?\d{4})?$/ }
42
+ ]
43
+
44
+ # this is the eventual list of countries, but we must first fill in all the pertinent info before we can switch to this list
45
+ # TODO: all the EU countries need their regional Europe distinction added, i.e. Southern Europe, South-Eastern Europe, etc.
46
+ PRIVATE_COUNTRIES = [
47
+ { :name => 'Afghanistan', :alpha2 => 'AF', :alpha3 => 'AFG', :numeric => '004', :continent => 'Asia', :region => ['Central Asia', 'Southern Asia', 'Central Asia', 'South-Central Asia', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /./i },
48
+ { :name => 'Albania', :alpha2 => 'AL', :alpha3 => 'ALB', :numeric => '008', :continent => 'Europe', :region => ['South-Eastern Europe', 'Southern Europe', 'Eastern Europe', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /./i },
49
+ { :name => 'Algeria', :alpha2 => 'DZ', :alpha3 => 'DZA', :numeric => '012', :continent => 'Africa', :region => ['North Africa', 'Northern Hemisphere', 'Eastern Hemisphere', 'Western Hemisphere'], :postal_code => postal4 },
50
+ { :name => 'American Samoa', :alpha2 => 'AS', :alpha3 => 'ASM', :numeric => '016', :continent => 'Asia', :region => ['South Pacific', 'United States Territory', 'Southern Hemisphere', 'Eastern Hemisphere'], :postal_code => /^\d{5}([\-\s]?\d{4})?$/ },
51
+ { :name => 'Andorra', :alpha2 => 'AD', :alpha3 => 'AND', :numeric => '020', :continent => 'Europe', :region => ['Southern Europe', 'Western Europe', 'South-Western Europe', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /^[A-Z]{2}\d{3}$/i },
52
+ { :name => 'Angola', :alpha2 => 'AO', :alpha3 => 'AGO', :numeric => '024', :continent => 'Africa', :region => ['Southern Africa', 'Central Africa', 'South-Central Africa', 'Southern Hemisphere', 'Eastern Hemisphere'], :postal_code => /./i },
53
+ { :name => 'Anguilla', :alpha2 => 'AI', :alpha3 => 'AIA', :numeric => '660', :continent => 'North America', :region => ['Special Territory of the European Union', 'Carribean', 'Northern Hemisphere', 'Western Hemisphere'], :postal_code => /./i },
54
+ { :name => 'Antigua and Barbuda', :alpha2 => 'AG', :alpha3 => 'ATG', :numeric => '028', :continent => 'North America', :region => ['Carribean', 'Northern Hemisphere', 'Western Hemisphere'], :postal_code => /./i },
55
+ { :name => 'Argentina', :alpha2 => 'AR', :alpha3 => 'ARG', :numeric => '032', :continent => 'South America', :region => ['Latin America''Northern Hemisphere', 'Western Hemisphere'], :postal_code => /^[A-Z]\d{4}[A-Z]{3}$/i },
56
+ { :name => 'Armenia', :alpha2 => 'AM', :alpha3 => 'ARM', :numeric => '051', :continent => 'Europe', :region => ['Eastern Europe', 'Southern Europe', 'South-Eastern Europe', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /^\d{6}$/i },
57
+ { :name => 'Aruba', :alpha2 => 'AW', :alpha3 => 'ABW', :numeric => '533', :continent => 'North America', :region => ['Carribean', 'Central America', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /./i },
58
+ { :name => 'Australia', :alpha2 => 'AU', :alpha3 => 'AUS', :numeric => '036', :continent => 'Australia', :region => ['Southern Hemisphere', 'Eastern Hemisphere', 'Australia', 'South Pacific'], :postal_code => postal4 },
59
+ { :name => 'Austria', :alpha2 => 'AT', :alpha3 => 'AUT', :numeric => '040', :continent => 'Europe', :region => ['EU', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => postal4 },
60
+ { :name => 'Åland Islands', :alpha2 => 'AX', :alpha3 => 'ALA', :numeric => '248', :continent => 'Europe', :region => ['Northern Europe''Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => /^([A-Z]{2})?[\-\s]?\d{5}$/i },
61
+ { :name => 'Azerbaijan', :alpha2 => 'AZ', :alpha3 => 'AZE', :numeric => '031', :continent => 'Europe', :region => ['Eastern Europe', 'Southern Europe', 'South-Eastern Europe', 'Northern Hemisphere', 'Eastern Hemisphere'], :postal_code => postal6 },
62
+ { :name => 'Bahamas', :alpha2 => 'BS', :alpha3 => 'BHS', :numeric => '044', :continent => 'North America', :region => ['Central America', 'Carribean', 'Northern Hemisphere', 'Western Hemisphere'], :postal_code => /./i },
63
+ { :name => 'Bahrain', :alpha2 => 'BH', :alpha3 => 'BHR', :numeric => '048', :continent => 'Europe', :region => [], :postal_code => /./i },
64
+ { :name => 'Bangladesh', :alpha2 => 'BD', :alpha3 => 'BGD', :numeric => '050', :continent => 'Europe', :region => [], :postal_code => /./i },
65
+ { :name => 'Barbados', :alpha2 => 'BB', :alpha3 => 'BRB', :numeric => '052', :continent => 'Europe', :region => [], :postal_code => /./i },
66
+ { :name => 'Belarus', :alpha2 => 'BY', :alpha3 => 'BLR', :numeric => '112', :continent => 'Europe', :region => [], :postal_code => /./i },
67
+ { :name => 'Belgium', :alpha2 => 'BE', :alpha3 => 'BEL', :numeric => '056', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
68
+ { :name => 'Belize', :alpha2 => 'BZ', :alpha3 => 'BLZ', :numeric => '084', :continent => 'Europe', :region => [], :postal_code => /./i },
69
+ { :name => 'Benin', :alpha2 => 'BJ', :alpha3 => 'BEN', :numeric => '204', :continent => 'Europe', :region => [], :postal_code => /./i },
70
+ { :name => 'Bermuda', :alpha2 => 'BM', :alpha3 => 'BMU', :numeric => '060', :continent => 'Europe', :region => [], :postal_code => /./i },
71
+ { :name => 'Bhutan', :alpha2 => 'BT', :alpha3 => 'BTN', :numeric => '064', :continent => 'Europe', :region => [], :postal_code => /./i },
72
+ { :name => 'Bolivia', :alpha2 => 'BO', :alpha3 => 'BOL', :numeric => '068', :continent => 'Europe', :region => [], :postal_code => /./i },
73
+ { :name => 'Bosnia and Herzegovina', :alpha2 => 'BA', :alpha3 => 'BIH', :numeric => '070', :continent => 'Europe', :region => [], :postal_code => /./i },
74
+ { :name => 'Botswana', :alpha2 => 'BW', :alpha3 => 'BWA', :numeric => '072', :continent => 'Europe', :region => [], :postal_code => /./i },
75
+ { :name => 'Brazil', :alpha2 => 'BR', :alpha3 => 'BRA', :numeric => '076', :continent => 'Europe', :region => [], :postal_code => /./i },
76
+ { :name => 'Brunei Darussalam', :alpha2 => 'BN', :alpha3 => 'BRN', :numeric => '096', :continent => 'Europe', :region => [], :postal_code => /./i },
77
+ { :name => 'Bulgaria', :alpha2 => 'BG', :alpha3 => 'BGR', :numeric => '100', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
78
+ { :name => 'Burkina Faso', :alpha2 => 'BF', :alpha3 => 'BFA', :numeric => '854', :continent => 'Europe', :region => [], :postal_code => /./i },
79
+ { :name => 'Burundi', :alpha2 => 'BI', :alpha3 => 'BDI', :numeric => '108', :continent => 'Europe', :region => [], :postal_code => /./i },
80
+ { :name => 'Cambodia', :alpha2 => 'KH', :alpha3 => 'KHM', :numeric => '116', :continent => 'Europe', :region => [], :postal_code => /./i },
81
+ { :name => 'Cameroon', :alpha2 => 'CM', :alpha3 => 'CMR', :numeric => '120', :continent => 'Europe', :region => [], :postal_code => /./i },
82
+ { :name => 'Canada', :alpha2 => 'CA', :alpha3 => 'CAN', :numeric => '124', :continent => 'North America', :region => ['Northern Hemisphere', 'Western Hemisphere', 'North America'], :postal_code => /^([A-Z]\d[A-Z][\-\s]?\d[A-Z](\d)?)$/i },
83
+ { :name => 'Cape Verde', :alpha2 => 'CV', :alpha3 => 'CPV', :numeric => '132', :continent => 'Europe', :region => [], :postal_code => /./i },
84
+ { :name => 'Cayman Islands', :alpha2 => 'KY', :alpha3 => 'CYM', :numeric => '136', :continent => 'Europe', :region => [], :postal_code => /./i },
85
+ { :name => 'Central African Republic', :alpha2 => 'CF', :alpha3 => 'CAF', :numeric => '140', :continent => 'Europe', :region => [], :postal_code => /./i },
86
+ { :name => 'Chad', :alpha2 => 'TD', :alpha3 => 'TCD', :numeric => '148', :continent => 'Europe', :region => [], :postal_code => /./i },
87
+ { :name => 'Chile', :alpha2 => 'CL', :alpha3 => 'CHL', :numeric => '152', :continent => 'Europe', :region => [], :postal_code => /./i },
88
+ { :name => 'China', :alpha2 => 'CN', :alpha3 => 'CHN', :numeric => '156', :continent => 'Europe', :region => [], :postal_code => /./i },
89
+ { :name => 'Colombia', :alpha2 => 'CO', :alpha3 => 'COL', :numeric => '170', :continent => 'Europe', :region => [], :postal_code => /./i },
90
+ { :name => 'Comoros', :alpha2 => 'KM', :alpha3 => 'COM', :numeric => '174', :continent => 'Europe', :region => [], :postal_code => /./i },
91
+ { :name => 'Congo', :alpha2 => 'CG', :alpha3 => 'COG', :numeric => '178', :continent => 'Europe', :region => [], :postal_code => /./i },
92
+ { :name => 'Congo, the Democratic Republic of the', :alpha2 => 'CD', :alpha3 => 'COD', :numeric => '180', :continent => 'Europe', :region => [], :postal_code => /./i },
93
+ { :name => 'Cook Islands', :alpha2 => 'CK', :alpha3 => 'COK', :numeric => '184', :continent => 'Europe', :region => [], :postal_code => /./i },
94
+ { :name => 'Costa Rica', :alpha2 => 'CR', :alpha3 => 'CRI', :numeric => '188', :continent => 'Europe', :region => [], :postal_code => /./i },
95
+ { :name => 'Cote D\'Ivoire', :alpha2 => 'CI', :alpha3 => 'CIV', :numeric => '384', :continent => 'Europe', :region => [], :postal_code => /./i },
96
+ { :name => 'Croatia', :alpha2 => 'HR', :alpha3 => 'HRV', :numeric => '191', :continent => 'Europe', :region => [], :postal_code => /./i },
97
+ { :name => 'Cuba', :alpha2 => 'CU', :alpha3 => 'CUB', :numeric => '192', :continent => 'Europe', :region => [], :postal_code => /./i },
98
+ { :name => 'Cyprus', :alpha2 => 'CY', :alpha3 => 'CYP', :numeric => '196', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
99
+ { :name => 'Czech Republic', :alpha2 => 'CZ', :alpha3 => 'CZE', :numeric => '203', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(CZ-)?\d{3}(\s)?\d{2}$/i },
100
+ { :name => 'Denmark', :alpha2 => 'DK', :alpha3 => 'DNK', :numeric => '208', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3,4}$/ },
101
+ { :name => 'Djibouti', :alpha2 => 'DJ', :alpha3 => 'DJI', :numeric => '262', :continent => 'Europe', :region => [], :postal_code => /./i },
102
+ { :name => 'Dominica', :alpha2 => 'DM', :alpha3 => 'DMA', :numeric => '212', :continent => 'Europe', :region => [], :postal_code => /./i },
103
+ { :name => 'Dominican Republic', :alpha2 => 'DO', :alpha3 => 'DOM', :numeric => '214', :continent => 'Europe', :region => [], :postal_code => /./i },
104
+ { :name => 'Ecuador', :alpha2 => 'EC', :alpha3 => 'ECU', :numeric => '218', :continent => 'Europe', :region => [], :postal_code => /./i },
105
+ { :name => 'Egypt', :alpha2 => 'EG', :alpha3 => 'EGY', :numeric => '818', :continent => 'Europe', :region => [], :postal_code => /./i },
106
+ { :name => 'El Salvador', :alpha2 => 'SV', :alpha3 => 'SLV', :numeric => '222', :continent => 'Europe', :region => [], :postal_code => /./i },
107
+ { :name => 'Equatorial Guinea', :alpha2 => 'GQ', :alpha3 => 'GNQ', :numeric => '226', :continent => 'Europe', :region => [], :postal_code => /./i },
108
+ { :name => 'Eritrea', :alpha2 => 'ER', :alpha3 => 'ERI', :numeric => '232', :continent => 'Europe', :region => [], :postal_code => /./i },
109
+ { :name => 'Estonia', :alpha2 => 'EE', :alpha3 => 'EST', :numeric => '233', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(EE-)?\d{4,5}$/i },
110
+ { :name => 'Ethiopia', :alpha2 => 'ET', :alpha3 => 'ETH', :numeric => '231', :continent => 'Europe', :region => [], :postal_code => /./i },
111
+ { :name => 'Falkland Islands (Malvinas)', :alpha2 => 'FK', :alpha3 => 'FLK', :numeric => '238', :continent => 'Europe', :region => [], :postal_code => /./i },
112
+ { :name => 'Faroe Islands', :alpha2 => 'FO', :alpha3 => 'FRO', :numeric => '234', :continent => 'Europe', :region => [], :postal_code => /./i },
113
+ { :name => 'Fiji', :alpha2 => 'FJ', :alpha3 => 'FJI', :numeric => '242', :continent => 'Europe', :region => [], :postal_code => /./i },
114
+ { :name => 'Finland', :alpha2 => 'FI', :alpha3 => 'FIN', :numeric => '246', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
115
+ { :name => 'France', :alpha2 => 'FR', :alpha3 => 'FRA', :numeric => '249', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
116
+ { :name => 'French Guiana', :alpha2 => 'GF', :alpha3 => 'GUF', :numeric => '254', :continent => 'Europe', :region => [], :postal_code => /./i },
117
+ { :name => 'French Polynesia', :alpha2 => 'PF', :alpha3 => 'PYF', :numeric => '258', :continent => 'Europe', :region => [], :postal_code => /./i },
118
+ { :name => 'Gabon', :alpha2 => 'GA', :alpha3 => 'GAB', :numeric => '266', :continent => 'Europe', :region => [], :postal_code => /./i },
119
+ { :name => 'Gambia', :alpha2 => 'GM', :alpha3 => 'GMB', :numeric => '270', :continent => 'Europe', :region => [], :postal_code => /./i },
120
+ { :name => 'Georgia', :alpha2 => 'GE', :alpha3 => 'GEO', :numeric => '268', :continent => 'Europe', :region => [], :postal_code => /./i },
121
+ { :name => 'Germany', :alpha2 => 'DE', :alpha3 => 'DEU', :numeric => '278', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
122
+ { :name => 'Ghana', :alpha2 => 'GH', :alpha3 => 'GHA', :numeric => '288', :continent => 'Europe', :region => [], :postal_code => /./i },
123
+ { :name => 'Gibraltar', :alpha2 => 'GI', :alpha3 => 'GIB', :numeric => '292', :continent => 'Europe', :region => [], :postal_code => /./i },
124
+ { :name => 'Greece', :alpha2 => 'GR', :alpha3 => 'GRC', :numeric => '300', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3}(\s)?\d{2}$/ },
125
+ { :name => 'Greenland', :alpha2 => 'GL', :alpha3 => 'GRL', :numeric => '304', :continent => 'Europe', :region => [], :postal_code => /./i },
126
+ { :name => 'Grenada', :alpha2 => 'GD', :alpha3 => 'GRD', :numeric => '308', :continent => 'Europe', :region => [], :postal_code => /./i },
127
+ { :name => 'Guadeloupe', :alpha2 => 'GP', :alpha3 => 'GLP', :numeric => '312', :continent => 'Europe', :region => [], :postal_code => /./i },
128
+ { :name => 'Guam', :alpha2 => 'GU', :alpha3 => 'GUM', :numeric => '316', :continent => 'Europe', :region => [], :postal_code => /./i },
129
+ { :name => 'Guatemala', :alpha2 => 'GT', :alpha3 => 'GTM', :numeric => '320', :continent => 'Europe', :region => [], :postal_code => /./i },
130
+ { :name => 'Guinea', :alpha2 => 'GN', :alpha3 => 'GIN', :numeric => '324', :continent => 'Europe', :region => [], :postal_code => /./i },
131
+ { :name => 'Guinea-Bissau', :alpha2 => 'GW', :alpha3 => 'GNB', :numeric => '624', :continent => 'Europe', :region => [], :postal_code => /./i },
132
+ { :name => 'Guyana', :alpha2 => 'GY', :alpha3 => 'GUY', :numeric => '328', :continent => 'Europe', :region => [], :postal_code => /./i },
133
+ { :name => 'Haiti', :alpha2 => 'HT', :alpha3 => 'HTI', :numeric => '332', :continent => 'Europe', :region => [], :postal_code => /./i },
134
+ { :name => 'Holy See (Vatican City State)', :alpha2 => 'VA', :alpha3 => 'VAT', :numeric => '336', :continent => 'Europe', :region => [], :postal_code => /./i },
135
+ { :name => 'Honduras', :alpha2 => 'HN', :alpha3 => 'HND', :numeric => '340', :continent => 'Europe', :region => [], :postal_code => /./i },
136
+ { :name => 'Hong Kong', :alpha2 => 'HK', :alpha3 => 'HKG', :numeric => '344', :continent => 'Europe', :region => [], :postal_code => /./i },
137
+ { :name => 'Hungary', :alpha2 => 'HU', :alpha3 => 'HUN', :numeric => '348', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
138
+ { :name => 'Iceland', :alpha2 => 'IS', :alpha3 => 'ISL', :numeric => '352', :continent => 'Europe', :region => [], :postal_code => /./i },
139
+ { :name => 'India', :alpha2 => 'IN', :alpha3 => 'IND', :numeric => '356', :continent => 'Europe', :region => [], :postal_code => /./i },
140
+ { :name => 'Indonesia', :alpha2 => 'ID', :alpha3 => 'IDN', :numeric => '360', :continent => 'Europe', :region => [], :postal_code => /./i },
141
+ { :name => 'Iran, Islamic Republic of', :alpha2 => 'IR', :alpha3 => 'IRN', :numeric => '364', :continent => 'Europe', :region => [], :postal_code => /./i },
142
+ { :name => 'Iraq', :alpha2 => 'IQ', :alpha3 => 'IRQ', :numeric => '368', :continent => 'Europe', :region => [], :postal_code => /./i },
143
+ { :name => 'Ireland', :alpha2 => 'IE', :alpha3 => 'IRL', :numeric => '372', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /.?/ },
144
+ { :name => 'Israel', :alpha2 => 'IL', :alpha3 => 'ISR', :numeric => '376', :continent => 'Europe', :region => [], :postal_code => /./i },
145
+ { :name => 'Italy', :alpha2 => 'IT', :alpha3 => 'ITA', :numeric => '380', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
146
+ { :name => 'Jamaica', :alpha2 => 'JM', :alpha3 => 'JAM', :numeric => '388', :continent => 'Europe', :region => [], :postal_code => /./i },
147
+ { :name => 'Japan', :alpha2 => 'JP', :alpha3 => 'JPN', :numeric => '392', :continent => 'Europe', :region => [], :postal_code => /./i },
148
+ { :name => 'Jordan', :alpha2 => 'JO', :alpha3 => 'JOR', :numeric => '400', :continent => 'Europe', :region => [], :postal_code => /./i },
149
+ { :name => 'Kazakhstan', :alpha2 => 'KZ', :alpha3 => 'KAZ', :numeric => '398', :continent => 'Europe', :region => [], :postal_code => /./i },
150
+ { :name => 'Kenya', :alpha2 => 'KE', :alpha3 => 'KEN', :numeric => '404', :continent => 'Europe', :region => [], :postal_code => /./i },
151
+ { :name => 'Kiribati', :alpha2 => 'KI', :alpha3 => 'KIR', :numeric => '296', :continent => 'Europe', :region => [], :postal_code => /./i },
152
+ { :name => 'Korea, Democratic People\'s Republic of', :alpha2 => 'KP', :alpha3 => 'PRK', :numeric => '408', :continent => 'Europe', :region => [], :postal_code => /./i },
153
+ { :name => 'Korea, Republic of', :alpha2 => 'KR', :alpha3 => 'KOR', :numeric => '410', :continent => 'Europe', :region => [], :postal_code => /./i },
154
+ { :name => 'Kuwait', :alpha2 => 'KW', :alpha3 => 'KWT', :numeric => '414', :continent => 'Europe', :region => [], :postal_code => /./i },
155
+ { :name => 'Kyrgyzstan', :alpha2 => 'KG', :alpha3 => 'KGZ', :numeric => '417', :continent => 'Europe', :region => [], :postal_code => /./i },
156
+ { :name => 'Lao People\'s Democratic Republic', :alpha2 => 'LA', :alpha3 => 'LAO', :numeric => '418', :continent => 'Europe', :region => [], :postal_code => /./i },
157
+ { :name => 'Latvia', :alpha2 => 'LV', :alpha3 => 'LVA', :numeric => '428', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /(LV-)?\d{4}^$/i },
158
+ { :name => 'Lebanon', :alpha2 => 'LB', :alpha3 => 'LBN', :numeric => '422', :continent => 'Europe', :region => [], :postal_code => /./i },
159
+ { :name => 'Lesotho', :alpha2 => 'LS', :alpha3 => 'LSO', :numeric => '426', :continent => 'Europe', :region => [], :postal_code => /./i },
160
+ { :name => 'Liberia', :alpha2 => 'LR', :alpha3 => 'LBR', :numeric => '430', :continent => 'Europe', :region => [], :postal_code => /./i },
161
+ { :name => 'Libyan Arab Jamahiriya', :alpha2 => 'LY', :alpha3 => 'LBY', :numeric => '434', :continent => 'Europe', :region => [], :postal_code => /./i },
162
+ { :name => 'Liechtenstein', :alpha2 => 'LI', :alpha3 => 'LIE', :numeric => '438', :continent => 'Europe', :region => [], :postal_code => /./i },
163
+ { :name => 'Lithuania', :alpha2 => 'LT', :alpha3 => 'LTU', :numeric => '440', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(LT-)?\d{5}$/i },
164
+ { :name => 'Luxembourg', :alpha2 => 'LU', :alpha3 => 'LUX', :numeric => '442', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal4 },
165
+ { :name => 'Macao', :alpha2 => 'MO', :alpha3 => 'MAC', :numeric => '446', :continent => 'Europe', :region => [], :postal_code => /./i },
166
+ { :name => 'Macedonia, the Former Yugoslav Republic of', :alpha2 => 'MK', :alpha3 => 'MKD', :numeric => '807', :continent => 'Europe', :region => [], :postal_code => /./i },
167
+ { :name => 'Madagascar', :alpha2 => 'MG', :alpha3 => 'MDG', :numeric => '450', :continent => 'Europe', :region => [], :postal_code => /./i },
168
+ { :name => 'Malawi', :alpha2 => 'MW', :alpha3 => 'MWI', :numeric => '454', :continent => 'Europe', :region => [], :postal_code => /./i },
169
+ { :name => 'Malaysia', :alpha2 => 'MY', :alpha3 => 'MYS', :numeric => '458', :continent => 'Europe', :region => [], :postal_code => /./i },
170
+ { :name => 'Maldives', :alpha2 => 'MV', :alpha3 => 'MDV', :numeric => '462', :continent => 'Europe', :region => [], :postal_code => /./i },
171
+ { :name => 'Mali', :alpha2 => 'ML', :alpha3 => 'MLI', :numeric => '466', :continent => 'Europe', :region => [], :postal_code => /./i },
172
+ { :name => 'Malta', :alpha2 => 'MT', :alpha3 => 'MLT', :numeric => '470', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^[A-Z]{3}(\s)?\d{4}$/i },
173
+ { :name => 'Marshall Islands', :alpha2 => 'MH', :alpha3 => 'MHL', :numeric => '584', :continent => 'Europe', :region => [], :postal_code => /./i },
174
+ { :name => 'Martinique', :alpha2 => 'MQ', :alpha3 => 'MTQ', :numeric => '474', :continent => 'Europe', :region => [], :postal_code => /./i },
175
+ { :name => 'Mauritania', :alpha2 => 'MR', :alpha3 => 'MRT', :numeric => '478', :continent => 'Europe', :region => [], :postal_code => /./i },
176
+ { :name => 'Mauritius', :alpha2 => 'MU', :alpha3 => 'MUS', :numeric => '480', :continent => 'Europe', :region => [], :postal_code => /./i },
177
+ { :name => 'Mexico', :alpha2 => 'MX', :alpha3 => 'MEX', :numeric => '484', :continent => 'Europe', :region => [], :postal_code => /./i },
178
+ { :name => 'Micronesia, Federated States of', :alpha2 => 'FM', :alpha3 => 'FSM', :numeric => '583', :continent => 'Europe', :region => [], :postal_code => /./i },
179
+ { :name => 'Moldova, Republic of', :alpha2 => 'MD', :alpha3 => 'MDA', :numeric => '498', :continent => 'Europe', :region => [], :postal_code => /./i },
180
+ { :name => 'Monaco', :alpha2 => 'MC', :alpha3 => 'MCO', :numeric => '492', :continent => 'Europe', :region => [], :postal_code => /./i },
181
+ { :name => 'Mongolia', :alpha2 => 'MN', :alpha3 => 'MNG', :numeric => '496', :continent => 'Europe', :region => [], :postal_code => /./i },
182
+ { :name => 'Montserrat', :alpha2 => 'MS', :alpha3 => 'MSR', :numeric => '500', :continent => 'Europe', :region => [], :postal_code => /./i },
183
+ { :name => 'Morocco', :alpha2 => 'MA', :alpha3 => 'MAR', :numeric => '504', :continent => 'Europe', :region => [], :postal_code => /./i },
184
+ { :name => 'Mozambique', :alpha2 => 'MZ', :alpha3 => 'MOZ', :numeric => '508', :continent => 'Europe', :region => [], :postal_code => /./i },
185
+ { :name => 'Myanmar', :alpha2 => 'MM', :alpha3 => 'MMR', :numeric => '104', :continent => 'Europe', :region => [], :postal_code => /./i },
186
+ { :name => 'Namibia', :alpha2 => 'NA', :alpha3 => 'NAM', :numeric => '516', :continent => 'Europe', :region => [], :postal_code => /./i },
187
+ { :name => 'Nauru', :alpha2 => 'NR', :alpha3 => 'NRU', :numeric => '520', :continent => 'Europe', :region => [], :postal_code => /./i },
188
+ { :name => 'Nepal', :alpha2 => 'NP', :alpha3 => 'NPL', :numeric => '524', :continent => 'Europe', :region => [], :postal_code => /./i },
189
+ { :name => 'Netherlands', :alpha2 => 'NL', :alpha3 => 'NLD', :numeric => '528', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{4}(\s)?[A-Z]{2}(\s)?(\d*)?$/ },
190
+ { :name => 'Netherlands Antilles', :alpha2 => 'AN', :alpha3 => 'ANT', :numeric => '530', :continent => 'Europe', :region => [], :postal_code => /./i },
191
+ { :name => 'New Caledonia', :alpha2 => 'NC', :alpha3 => 'NCL', :numeric => '540', :continent => 'Europe', :region => [], :postal_code => /./i },
192
+ { :name => 'New Zealand', :alpha2 => 'NZ', :alpha3 => 'NZL', :numeric => '554', :continent => 'Europe', :region => [], :postal_code => /./i },
193
+ { :name => 'Nicaragua', :alpha2 => 'NI', :alpha3 => 'NIC', :numeric => '558', :continent => 'Europe', :region => [], :postal_code => /./i },
194
+ { :name => 'Niger', :alpha2 => 'NE', :alpha3 => 'NER', :numeric => '562', :continent => 'Europe', :region => [], :postal_code => /./i },
195
+ { :name => 'Nigeria', :alpha2 => 'NG', :alpha3 => 'NGA', :numeric => '566', :continent => 'Europe', :region => [], :postal_code => /./i },
196
+ { :name => 'Niue', :alpha2 => 'NU', :alpha3 => 'NIU', :numeric => '570', :continent => 'Europe', :region => [], :postal_code => /./i },
197
+ { :name => 'Norfolk Island', :alpha2 => 'NF', :alpha3 => 'NFK', :numeric => '574', :continent => 'Europe', :region => [], :postal_code => /./i },
198
+ { :name => 'Northern Mariana Islands', :alpha2 => 'MP', :alpha3 => 'MNP', :numeric => '580', :continent => 'Europe', :region => [], :postal_code => /./i },
199
+ { :name => 'Norway', :alpha2 => 'NO', :alpha3 => 'NOR', :numeric => '578', :continent => 'Europe', :region => [], :postal_code => /./i },
200
+ { :name => 'Oman', :alpha2 => 'OM', :alpha3 => 'OMN', :numeric => '512', :continent => 'Europe', :region => [], :postal_code => /./i },
201
+ { :name => 'Pakistan', :alpha2 => 'PK', :alpha3 => 'PAK', :numeric => '586', :continent => 'Europe', :region => [], :postal_code => /./i },
202
+ { :name => 'Palau', :alpha2 => 'PW', :alpha3 => 'PLW', :numeric => '585', :continent => 'Europe', :region => [], :postal_code => /./i },
203
+ { :name => 'Panama', :alpha2 => 'PA', :alpha3 => 'PAN', :numeric => '591', :continent => 'North America', :region => [], :postal_code => /./i },
204
+ { :name => 'Papua New Guinea', :alpha2 => 'PG', :alpha3 => 'PNG', :numeric => '598', :continent => 'Europe', :region => [], :postal_code => /./i },
205
+ { :name => 'Paraguay', :alpha2 => 'PY', :alpha3 => 'PRY', :numeric => '600', :continent => 'Europe', :region => [], :postal_code => /./i },
206
+ { :name => 'Peru', :alpha2 => 'PE', :alpha3 => 'PER', :numeric => '604', :continent => 'Europe', :region => [], :postal_code => /./i },
207
+ { :name => 'Philippines', :alpha2 => 'PH', :alpha3 => 'PHL', :numeric => '608', :continent => 'Europe', :region => [], :postal_code => /./i },
208
+ { :name => 'Pitcairn', :alpha2 => 'PN', :alpha3 => 'PCN', :numeric => '612', :continent => 'Europe', :region => [], :postal_code => /./i },
209
+ { :name => 'Poland', :alpha2 => 'PL', :alpha3 => 'POL', :numeric => '616', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{2}[\-\s]?\d{3}$/ },
210
+ { :name => 'Portugal', :alpha2 => 'PT', :alpha3 => 'PRT', :numeric => '620', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{4}[\-\s]?\d{3}$/ },
211
+ { :name => 'Puerto Rico', :alpha2 => 'PR', :alpha3 => 'PRI', :numeric => '630', :continent => 'Europe', :region => [], :postal_code => /./i },
212
+ { :name => 'Qatar', :alpha2 => 'QA', :alpha3 => 'QAT', :numeric => '634', :continent => 'Europe', :region => [], :postal_code => /./i },
213
+ { :name => 'Reunion', :alpha2 => 'RE', :alpha3 => 'REU', :numeric => '638', :continent => 'Europe', :region => [], :postal_code => /./i },
214
+ { :name => 'Romania', :alpha2 => 'RO', :alpha3 => 'ROM', :numeric => '642', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{6}$/ },
215
+ { :name => 'Russian Federation', :alpha2 => 'RU', :alpha3 => 'RUS', :numeric => '643', :continent => 'Europe', :region => [], :postal_code => /./i },
216
+ { :name => 'Rwanda', :alpha2 => 'RW', :alpha3 => 'RWA', :numeric => '646', :continent => 'Europe', :region => [], :postal_code => /./i },
217
+ { :name => 'Saint Helena', :alpha2 => 'SH', :alpha3 => 'SHN', :numeric => '654', :continent => 'Europe', :region => [], :postal_code => /./i },
218
+ { :name => 'Saint Kitts and Nevis', :alpha2 => 'KN', :alpha3 => 'KNA', :numeric => '659', :continent => 'Europe', :region => [], :postal_code => /./i },
219
+ { :name => 'Saint Lucia', :alpha2 => 'LC', :alpha3 => 'LCA', :numeric => '662', :continent => 'Europe', :region => [], :postal_code => /./i },
220
+ { :name => 'Saint Pierre and Miquelon', :alpha2 => 'PM', :alpha3 => 'SPM', :numeric => '666', :continent => 'Europe', :region => [], :postal_code => /./i },
221
+ { :name => 'Saint Vincent and the Grenadines', :alpha2 => 'VC', :alpha3 => 'VCT', :numeric => '670', :continent => 'Europe', :region => [], :postal_code => /./i },
222
+ { :name => 'Samoa', :alpha2 => 'WS', :alpha3 => 'WSM', :numeric => '882', :continent => 'Europe', :region => [], :postal_code => /./i },
223
+ { :name => 'San Marino', :alpha2 => 'SM', :alpha3 => 'SMR', :numeric => '674', :continent => 'Europe', :region => [], :postal_code => /./i },
224
+ { :name => 'Sao Tome and Principe', :alpha2 => 'ST', :alpha3 => 'STP', :numeric => '678', :continent => 'Europe', :region => [], :postal_code => /./i },
225
+ { :name => 'Saudi Arabia', :alpha2 => 'SA', :alpha3 => 'SAU', :numeric => '682', :continent => 'Europe', :region => [], :postal_code => /./i },
226
+ { :name => 'Senegal', :alpha2 => 'SN', :alpha3 => 'SEN', :numeric => '686', :continent => 'Europe', :region => [], :postal_code => /./i },
227
+ { :name => 'Seychelles', :alpha2 => 'SC', :alpha3 => 'SYC', :numeric => '690', :continent => 'Europe', :region => [], :postal_code => /./i },
228
+ { :name => 'Sierra Leone', :alpha2 => 'SL', :alpha3 => 'SLE', :numeric => '694', :continent => 'Europe', :region => [], :postal_code => /./i },
229
+ { :name => 'Singapore', :alpha2 => 'SG', :alpha3 => 'SGP', :numeric => '702', :continent => 'Europe', :region => [], :postal_code => /./i },
230
+ { :name => 'Slovakia', :alpha2 => 'SK', :alpha3 => 'SVK', :numeric => '703', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(SK-)?\d{3}(\s)?\d{2}$/ },
231
+ { :name => 'Slovenia', :alpha2 => 'SI', :alpha3 => 'SVN', :numeric => '705', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^(SL-)?\d{4}$/i },
232
+ { :name => 'Solomon Islands', :alpha2 => 'SB', :alpha3 => 'SLB', :numeric => '090', :continent => 'Europe', :region => [], :postal_code => /./i },
233
+ { :name => 'Somalia', :alpha2 => 'SO', :alpha3 => 'SOM', :numeric => '706', :continent => 'Europe', :region => [], :postal_code => /./i },
234
+ { :name => 'South Africa', :alpha2 => 'ZA', :alpha3 => 'ZAF', :numeric => '710', :continent => 'Europe', :region => [], :postal_code => /./i },
235
+ { :name => 'Spain', :alpha2 => 'ES', :alpha3 => 'ESP', :numeric => '724', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => postal5 },
236
+ { :name => 'Sri Lanka', :alpha2 => 'LK', :alpha3 => 'LKA', :numeric => '144', :continent => 'Europe', :region => [], :postal_code => /./i },
237
+ { :name => 'Sudan', :alpha2 => 'SD', :alpha3 => 'SDN', :numeric => '736', :continent => 'Europe', :region => [], :postal_code => /./i },
238
+ { :name => 'Suriname', :alpha2 => 'SR', :alpha3 => 'SUR', :numeric => '740', :continent => 'Europe', :region => [], :postal_code => /./i },
239
+ { :name => 'Svalbard and Jan Mayen', :alpha2 => 'SJ', :alpha3 => 'SJM', :numeric => '744', :continent => 'Europe', :region => [], :postal_code => /./i },
240
+ { :name => 'Swaziland', :alpha2 => 'SZ', :alpha3 => 'SWZ', :numeric => '748', :continent => 'Europe', :region => [], :postal_code => /./i },
241
+ { :name => 'Sweden', :alpha2 => 'SE', :alpha3 => 'SWE', :numeric => '752', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^\d{3}(\s)?\d{2}$/ },
242
+ { :name => 'Switzerland', :alpha2 => 'CH', :alpha3 => 'CHE', :numeric => '756', :continent => 'Europe', :region => [], :postal_code => /./i },
243
+ { :name => 'Syrian Arab Republic', :alpha2 => 'SY', :alpha3 => 'SYR', :numeric => '760', :continent => 'Europe', :region => [], :postal_code => /./i },
244
+ { :name => 'Taiwan, Province of China', :alpha2 => 'TW', :alpha3 => 'TWN', :numeric => '158', :continent => 'Europe', :region => [], :postal_code => /./i },
245
+ { :name => 'Tajikistan', :alpha2 => 'TJ', :alpha3 => 'TJK', :numeric => '762', :continent => 'Europe', :region => [], :postal_code => /./i },
246
+ { :name => 'Tanzania, United Republic of', :alpha2 => 'TZ', :alpha3 => 'TZA', :numeric => '834', :continent => 'Europe', :region => [], :postal_code => /./i },
247
+ { :name => 'Thailand', :alpha2 => 'TH', :alpha3 => 'THA', :numeric => '764', :continent => 'Europe', :region => [], :postal_code => /./i },
248
+ { :name => 'Togo', :alpha2 => 'TG', :alpha3 => 'TGO', :numeric => '768', :continent => 'Europe', :region => [], :postal_code => /./i },
249
+ { :name => 'Tokelau', :alpha2 => 'TK', :alpha3 => 'TKL', :numeric => '772', :continent => 'Europe', :region => [], :postal_code => /./i },
250
+ { :name => 'Tonga', :alpha2 => 'TO', :alpha3 => 'TON', :numeric => '776', :continent => 'Europe', :region => [], :postal_code => /./i },
251
+ { :name => 'Trinidad and Tobago', :alpha2 => 'TT', :alpha3 => 'TTO', :numeric => '780', :continent => 'Europe', :region => [], :postal_code => /./i },
252
+ { :name => 'Tunisia', :alpha2 => 'TN', :alpha3 => 'TUN', :numeric => '788', :continent => 'Europe', :region => [], :postal_code => /./i },
253
+ { :name => 'Turkey', :alpha2 => 'TR', :alpha3 => 'TUR', :numeric => '792', :continent => 'Europe', :region => [], :postal_code => /./i },
254
+ { :name => 'Turkmenistan', :alpha2 => 'TM', :alpha3 => 'TKM', :numeric => '795', :continent => 'Europe', :region => [], :postal_code => /./i },
255
+ { :name => 'Turks and Caicos Islands', :alpha2 => 'TC', :alpha3 => 'TCA', :numeric => '796', :continent => 'Europe', :region => [], :postal_code => /./i },
256
+ { :name => 'Tuvalu', :alpha2 => 'TV', :alpha3 => 'TUV', :numeric => '798', :continent => 'Europe', :region => [], :postal_code => /./i },
257
+ { :name => 'Uganda', :alpha2 => 'UG', :alpha3 => 'UGA', :numeric => '800', :continent => 'Europe', :region => [], :postal_code => /./i },
258
+ { :name => 'Ukraine', :alpha2 => 'UA', :alpha3 => 'UKR', :numeric => '804', :continent => 'Europe', :region => [], :postal_code => /./i },
259
+ { :name => 'United Arab Emirates', :alpha2 => 'AE', :alpha3 => 'ARE', :numeric => '784', :continent => 'Europe', :region => [], :postal_code => /./i },
260
+ { :name => 'United Kingdom', :alpha2 => 'GB', :alpha3 => 'GBR', :numeric => '826', :continent => 'Europe', :region => ['Northern Hemisphere', 'Eastern Hemisphere', 'EU'], :postal_code => /^[\dA-Z]{2,4}(\s)?[\dA-Z]{3}$/i },
261
+ { :name => 'United States', :alpha2 => 'US', :alpha3 => 'USA', :numeric => '840', :continent => 'North America', :region => ['Northern Hemisphere', 'Western Hemisphere', 'North America'], :postal_code => /^\d{5}([\-\s]?\d{4})?$/ },
262
+ { :name => 'United States Minor Outlying Islands', :alpha2 => 'UM', :alpha3 => 'UMI', :numeric => '849', :continent => 'North America', :region => ['Northern Hemisphere', 'Western Hemisphere', 'North America'], :postal_code => /^\d{5}([\-\s]?\d{4})?$/ },
263
+ { :name => 'Uruguay', :alpha2 => 'UY', :alpha3 => 'URY', :numeric => '858', :continent => 'Europe', :region => [], :postal_code => /./i },
264
+ { :name => 'Uzbekistan', :alpha2 => 'UZ', :alpha3 => 'UZB', :numeric => '860', :continent => 'Europe', :region => [], :postal_code => /./i },
265
+ { :name => 'Vanuatu', :alpha2 => 'VU', :alpha3 => 'VUT', :numeric => '548', :continent => 'Europe', :region => [], :postal_code => /./i },
266
+ { :name => 'Venezuela', :alpha2 => 'VE', :alpha3 => 'VEN', :numeric => '862', :continent => 'Europe', :region => [], :postal_code => /./i },
267
+ { :name => 'Viet Nam', :alpha2 => 'VN', :alpha3 => 'VNM', :numeric => '704', :continent => 'Europe', :region => [], :postal_code => /./i },
268
+ { :name => 'Virgin Islands, British', :alpha2 => 'VG', :alpha3 => 'VGB', :numeric => '092', :continent => 'Europe', :region => [], :postal_code => /./i },
269
+ { :name => 'Virgin Islands, U.S.', :alpha2 => 'VI', :alpha3 => 'VIR', :numeric => '850', :continent => 'Europe', :region => [], :postal_code => /./i },
270
+ { :name => 'Wallis and Futuna', :alpha2 => 'WF', :alpha3 => 'WLF', :numeric => '876', :continent => 'Europe', :region => [], :postal_code => /./i },
271
+ { :name => 'Western Sahara', :alpha2 => 'EH', :alpha3 => 'ESH', :numeric => '732', :continent => 'Europe', :region => [], :postal_code => /./i },
272
+ { :name => 'Yemen', :alpha2 => 'YE', :alpha3 => 'YEM', :numeric => '887', :continent => 'Europe', :region => [], :postal_code => /./i },
273
+ { :name => 'Zambia', :alpha2 => 'ZM', :alpha3 => 'ZMB', :numeric => '894', :continent => 'Europe', :region => [], :postal_code => /./i },
274
+ { :name => 'Zimbabwe', :alpha2 => 'ZW', :alpha3 => 'ZWE', :numeric => '716', :continent => 'Europe', :region => [], :postal_code => /./i }
275
+ ]
276
+
277
+ searchable_config do |c|
278
+ # c.list = COUNTRIES
279
+ c.list = PRIVATE_COUNTRIES
280
+ c.attributes = [:name, :numeric, :alpha2, :alpha3, :continent, :region]
281
+ c.aliases = [
282
+ {:abbr => [:alpha2, :alpha3] },
283
+ {:abbreviation => [:alpha2, :alpha3] },
284
+ {:iso => :numeric },
285
+ {:iso_code => :numeric },
286
+ {:code => :numeric}
287
+ ]
288
+ end
289
+
290
+ def self.countries
291
+ PRIVATE_COUNTRIES
292
+ end
293
+
294
+ def self.names(_cty=self.countries)
295
+ _cty.collect{|c| c[:name]}
296
+ end
297
+
298
+ def self.abbreviations(_cty=self.countries)
299
+ _cty.collect{|c| [c[:alpha2], c[:alpha3]] }
300
+ end
301
+
302
+ def self.iso_codes(_cty=self.countries)
303
+ _cty.collect{|c| c[:numeric]}
304
+ end
305
+
306
+ def self.north_america
307
+ find_all('North America', :region)
308
+ end
309
+
310
+ def self.north_america?(cty)
311
+ in_this_region?(cty, :north_america)
312
+ end
313
+
314
+ def self.eu
315
+ find_all('EU', :region)
316
+ end
317
+
318
+ def self.eu?(cty)
319
+ in_this_region?(cty, :eu)
320
+ end
321
+
322
+ def self.where_is_zip_valid(zip)
323
+ countries.select{|c| zip =~ c[:postal_code] } # .sort{|a,b| a[:priority] <=> b[:priority] }
324
+ end
325
+
326
+ def self.region(cty)
327
+ if in_this_region?(cty, :north_america)
328
+ :north_america
329
+ elsif in_this_region?(cty, :eu)
330
+ :eu
331
+ else
332
+ nil
333
+ end
334
+ end
335
+
336
+
337
+ protected
338
+
339
+ def self.in_this_region?(cty, region)
340
+ cty = cty.is_a?(Hash) ? cty[:name] : cty
341
+ send(region).collect{|c| c[:name]}.include?(cty)
342
+ end
343
+
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,42 @@
1
+ module Validatious
2
+ module Addresses
3
+ module Provinces
4
+ include Searchable
5
+
6
+ PROVINCES = [
7
+ {:name => 'ALBERTA', :alpha => 'AB'},
8
+ {:name => 'BRITISH COLUMBIA', :alpha => 'BC'},
9
+ {:name => 'MANITOBA', :alpha => 'MT'},
10
+ {:name => 'NEW BRUNSWICK', :alpha => 'NB'},
11
+ {:name => 'NEWFOUNDLAND AND LABRADOR', :alpha => 'NL'},
12
+ {:name => 'NORTHWEST TERRITORIES', :alpha => 'NT'},
13
+ {:name => 'NOVA SCOTIA', :alpha => 'NS'},
14
+ {:name => 'NUNAVUT', :alpha => 'NV'},
15
+ {:name => 'ONTARIO', :alpha => 'ON'},
16
+ {:name => 'PRINCE EDWARD ISLAND', :alpha => 'PE'},
17
+ {:name => 'QUEBEC', :alpha => 'QB'},
18
+ {:name => 'SASKATCHEWAN', :alpha => 'SK'},
19
+ {:name => 'YUKON', :alpha => 'YK'}
20
+ ]
21
+
22
+ searchable_config do |c|
23
+ c.list = PROVINCES
24
+ c.attributes = [:name, :alpha]
25
+ c.aliases = [ {:abbr => :alpha}, {:abbreviation => :alpha} ]
26
+ end
27
+
28
+ def self.provinces
29
+ PROVINCES.dup
30
+ end
31
+
32
+ def self.names(_cty=self.provinces)
33
+ _cty.collect{|c| c[:name]}
34
+ end
35
+
36
+ def self.abbreviations(_cty=self.provinces)
37
+ _cty.collect{|c| c[:alpha] }
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,90 @@
1
+ module Validatious
2
+ module Addresses
3
+ module Searchable
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def self.extended(object)
11
+ object.class_eval{
12
+ @attributes = []
13
+ @aliases = []
14
+ @list = []
15
+ }
16
+
17
+ class << object
18
+ attr_accessor :attributes, :aliases, :list
19
+ end
20
+ end
21
+
22
+ def searchable_config(&block)
23
+ # just send the object back to the block for configuration -- it might be good to create methods to update configuration
24
+ yield self
25
+ end
26
+
27
+ def find(term, field=:name)
28
+ search(:find, term, field)
29
+ end
30
+
31
+ def find_all(term, field=:name)
32
+ search(:find_all, term, field)
33
+ end
34
+
35
+
36
+ protected
37
+
38
+ def method_missing(method, *args, &block)
39
+ m = method.to_s.match(/^(find_all)_by_(.+)$/i)
40
+ m ||= method.to_s.match(/^(find)_by_(.+)$/i)
41
+
42
+ return super unless m && args.length == 1
43
+ send(m.captures.first.to_sym, args.first, m.captures.last.to_sym)
44
+ end
45
+
46
+ def define_search_field(field)
47
+ if field.is_a?(Array)
48
+ multiple_fields = []
49
+ field.each do |v|
50
+ unless @attributes.include?(v)
51
+ new_field = []
52
+ @aliases.each{|al|
53
+ new_field << al[al.keys.first] if al.keys.first.to_s.downcase == v.to_s.downcase
54
+ }
55
+ else
56
+ new_field = v
57
+ end
58
+ multiple_fields << new_field if new_field
59
+ end
60
+ return multiple_fields.flatten.uniq
61
+ elsif !@attributes.include?(field)
62
+ field = @aliases.find{|a| a.keys.first.to_s.downcase == field.to_s.downcase}
63
+ field = field.values.first
64
+ end
65
+ field
66
+ end
67
+
68
+ def search(method, term, field)
69
+ field = define_search_field(field)
70
+
71
+ if field.is_a?(Array)
72
+ @list.send(method){|c|
73
+ found = false
74
+ field.each do |key|
75
+ next if found
76
+ found = c[key].is_a?(Array) ? c[key].map(&:upcase).include?(term.to_s.upcase) : (c[key].upcase == term.to_s.upcase)
77
+ end
78
+ found
79
+ }
80
+ else
81
+ @list.send(method){|c|
82
+ c[field].is_a?(Array) ? c[field].map(&:upcase).include?(term.to_s.upcase) : (c[field].upcase == term.to_s.upcase)
83
+ }
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,102 @@
1
+ module Validatious
2
+ module Addresses
3
+ module States
4
+ include Validatious::Addresses::Searchable
5
+
6
+ # TODO: Titlecase state names (instead of uppercase)
7
+ STATES = [
8
+ { :name => 'ALABAMA', :alpha => 'AL' },
9
+ { :name => 'ALASKA', :alpha => 'AK' },
10
+ { :name => 'AMERICAN SAMOA', :alpha => 'AS' },
11
+ { :name => 'ARIZONA', :alpha => 'AZ' },
12
+ { :name => 'ARKANSAS', :alpha => 'AR' },
13
+ { :name => 'CALIFORNIA', :alpha => 'CA' },
14
+ { :name => 'COLORADO', :alpha => 'CO' },
15
+ { :name => 'CONNECTICUT', :alpha => 'CT' },
16
+ { :name => 'DELAWARE', :alpha => 'DE' },
17
+ { :name => 'DISTRICT OF COLUMBIA', :alpha => 'DC' },
18
+ { :name => 'FEDERATED STATES OF MICRONESIA', :alpha => 'FM' },
19
+ { :name => 'FLORIDA', :alpha => 'FL' },
20
+ { :name => 'GEORGIA', :alpha => 'GA' },
21
+ { :name => 'GUAM', :alpha => 'GU' },
22
+ { :name => 'HAWAII', :alpha => 'HI' },
23
+ { :name => 'IDAHO', :alpha => 'ID' },
24
+ { :name => 'ILLINOIS', :alpha => 'IL' },
25
+ { :name => 'INDIANA', :alpha => 'IN' },
26
+ { :name => 'IOWA', :alpha => 'IA' },
27
+ { :name => 'KANSAS', :alpha => 'KS' },
28
+ { :name => 'KENTUCKY', :alpha => 'KY' },
29
+ { :name => 'LOUISIANA', :alpha => 'LA' },
30
+ { :name => 'MAINE', :alpha => 'ME' },
31
+ { :name => 'MARSHALL ISLANDS', :alpha => 'MH' },
32
+ { :name => 'MARYLAND', :alpha => 'MD' },
33
+ { :name => 'MASSACHUSETTS', :alpha => 'MA' },
34
+ { :name => 'MICHIGAN', :alpha => 'MI' },
35
+ { :name => 'MINNESOTA', :alpha => 'MN' },
36
+ { :name => 'MISSISSIPPI', :alpha => 'MS' },
37
+ { :name => 'MISSOURI', :alpha => 'MO' },
38
+ { :name => 'MONTANA', :alpha => 'MT' },
39
+ { :name => 'NEBRASKA', :alpha => 'NE' },
40
+ { :name => 'NEVADA', :alpha => 'NV' },
41
+ { :name => 'NEW HAMPSHIRE', :alpha => 'NH' },
42
+ { :name => 'NEW JERSEY', :alpha => 'NJ' },
43
+ { :name => 'NEW MEXICO', :alpha => 'NM' },
44
+ { :name => 'NEW YORK', :alpha => 'NY' },
45
+ { :name => 'NORTH CAROLINA', :alpha => 'NC' },
46
+ { :name => 'NORTH DAKOTA', :alpha => 'ND' },
47
+ { :name => 'NORTHERN MARIANA ISLANDS', :alpha => 'MP' },
48
+ { :name => 'OHIO', :alpha => 'OH' },
49
+ { :name => 'OKLAHOMA', :alpha => 'OK' },
50
+ { :name => 'OREGON', :alpha => 'OR' },
51
+ { :name => 'PALAU', :alpha => 'PW' },
52
+ { :name => 'PENNSYLVANIA', :alpha => 'PA' },
53
+ { :name => 'PUERTO RICO', :alpha => 'PR' },
54
+ { :name => 'RHODE ISLAND', :alpha => 'RI' },
55
+ { :name => 'SOUTH CAROLINA', :alpha => 'SC' },
56
+ { :name => 'SOUTH DAKOTA', :alpha => 'SD' },
57
+ { :name => 'TENNESSEE', :alpha => 'TN' },
58
+ { :name => 'TEXAS', :alpha => 'TX' },
59
+ { :name => 'UTAH', :alpha => 'UT' },
60
+ { :name => 'VERMONT', :alpha => 'VT' },
61
+ { :name => 'VIRGIN ISLANDS', :alpha => 'VI' },
62
+ { :name => 'VIRGINIA', :alpha => 'VA' },
63
+ { :name => 'WASHINGTON', :alpha => 'WA' },
64
+ { :name => 'WEST VIRGINIA', :alpha => 'WV' },
65
+ { :name => 'WISCONSIN', :alpha => 'WI' },
66
+ { :name => 'WYOMING', :alpha => 'WY' }
67
+ ]
68
+
69
+ searchable_config do |c|
70
+ c.list = STATES
71
+ c.attributes = [:name, :alpha]
72
+ c.aliases = [ {:abbr => :alpha}, {:abbreviation => :alpha} ]
73
+ end
74
+
75
+ def self.states
76
+ STATES.dup
77
+ end
78
+
79
+ def self.names(_cty=self.states)
80
+ _cty.collect{|c| c[:name]}
81
+ end
82
+
83
+ def self.abbreviations(_cty=self.states)
84
+ _cty.collect{|c| c[:alpha] }
85
+ end
86
+
87
+
88
+ protected
89
+
90
+ def self.find_collection(terms, field=:name)
91
+ terms = terms.is_a?(Array) ? terms : terms.to_a
92
+ results =[]
93
+ terms.each do |term|
94
+ r = find(term, field)
95
+ results << r if r
96
+ end
97
+ results
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -10,6 +10,10 @@ module ActiveModel
10
10
  validates_with EmailValidator, _merge_attributes(attr_names)
11
11
  end
12
12
 
13
+ def validates_postal_code_format_of(*attr_names)
14
+ validates_with PostalCodeValidator, _merge_attributes(attr_names)
15
+ end
16
+
13
17
  def validates_text_content_of(*attr_names)
14
18
  validates_with TextContentValidator, _merge_attributes(attr_names)
15
19
  end
@@ -2,5 +2,6 @@ en:
2
2
  errors:
3
3
  messages:
4
4
  invalid_url: "is not a valid URL"
5
+ invalid_postal_code: "is not a valid postal code"
5
6
  invalid_email: "is not a valid email address"
6
7
  invalid_text_content: "has incorrect capitalization and punctuation. (ie: All sentences should begin with a capital letter and end with a punctuation mark, etc.)"
@@ -0,0 +1,49 @@
1
+ module Validatious
2
+ module Validators
3
+
4
+ # == Active Model Postal Code Validator
5
+ class PostalCodeValidator < ActiveModel::EachValidator
6
+
7
+ def validate_each(record, attribute, value)
8
+ countries = options[:country].is_a?(Array) ? options[:country] : [options[:country]]
9
+
10
+ countries = countries.map do |name|
11
+ country = case
12
+ when name.is_a?(Symbol)
13
+ record.send name
14
+ when name.is_a?(Hash)
15
+ c_obj = record.send(name.keys.first)
16
+ c_obj ? c_obj.send(name[name.keys.first]) : nil
17
+ else
18
+ name.blank? ? 'USA' : name
19
+ end
20
+
21
+ regex = nil
22
+ Validatious::Addresses::Countries.countries.each do |config|
23
+ if country =~ /^(#{config[:name]}|#{config[:alpha2]}|#{config[:alpha3]})$/i
24
+ regex = config[:postal_code]
25
+ break
26
+ end
27
+ end
28
+
29
+ regex
30
+ end.compact
31
+
32
+ if countries.empty?
33
+ record.errors.add :base, "A valid country must be provided for " +
34
+ "#{attribute.to_s.humanize.downcase} validation."
35
+ else
36
+ valid = countries.map do |regex|
37
+ !(value.to_s =~ /^#{regex}$/i).nil? ? true : nil
38
+ end.compact
39
+
40
+ record.errors.add attribute, :invalid_postal_code, options if valid.empty?
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+
48
+ # Compatibility with ActiveModel validates method which matches option keys to their validator class
49
+ ActiveModel::Validations::PostalCodeValidator = Validatious::Validators::PostalCodeValidator
@@ -1,3 +1,3 @@
1
1
  module Validatious
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -15,4 +15,8 @@ RSpec.configure do |config|
15
15
  config.after(:all) do
16
16
  DeferredGarbageCollection.reconsider
17
17
  end
18
+
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+ config.filter_run :focus => true
21
+ config.run_all_when_everything_filtered = true
18
22
  end
@@ -0,0 +1,13 @@
1
+ class Person
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Validations::Callbacks
4
+
5
+ attr_accessor :postal_code
6
+
7
+ def initialize(attributes = {})
8
+ attributes.each do |key, value|
9
+ send "#{key}=", value
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validatious::Addresses::Countries do
4
+
5
+ describe ".find_by_name" do
6
+ it "should return proper country" do
7
+ subject.find_by_name('United States')[:name].should == 'United States'
8
+ subject.find_by_name('France')[:numeric].should == "249"
9
+ end
10
+
11
+ it "should be case insensitive" do
12
+ subject.find_by_name('CzEcH REPublIC')[:alpha3].should == 'CZE'
13
+ subject.find_by_name('SLOvakia')[:alpha2].should == 'SK'
14
+ end
15
+ end
16
+
17
+ describe ".find_by_alpha2" do
18
+ it { subject.find_by_alpha2('US')[:alpha3].should == 'USA' }
19
+ end
20
+
21
+ describe ".find_by_alpha3" do
22
+ it { subject.find_by_alpha3('USA')[:alpha2].should == 'US' }
23
+ end
24
+
25
+ describe "the regular old find method with multiple field search" do
26
+ it { subject.find('United States', [:name, :alpha2, :alpha3])[:alpha2].should == 'US' }
27
+ it { subject.find('AU', [:name, :alpha2, :alpha3])[:alpha2].should == 'AU' }
28
+ it { subject.find('249', [:iso_code, :name])[:name].should == 'France' }
29
+ end
30
+
31
+ describe "find_by methods return same object" do
32
+ it { subject.find_by_alpha2('US').should == subject.find_by_alpha3('USA') }
33
+ it { subject.find_by_name('United States').should == subject.find_by_abbr('US') }
34
+ it { subject.find_by_abbr('USA').should == subject.find_by_iso_code('840') }
35
+ end
36
+
37
+ describe ".where_is_zip_valid" do
38
+ it { subject.where_is_zip_valid('123KKK9093450').length.should == 191 }
39
+ it { subject.where_is_zip_valid('67013').should include(subject.find_by_abbr('USA')) }
40
+ end
41
+
42
+ describe ".eu?" do
43
+ it { subject.eu?('France').should be_true }
44
+ it { subject.eu?('Czech Republic').should be_true }
45
+ it { subject.eu?(subject.find_by_name('United Kingdom')).should be_true }
46
+ it { subject.eu?('United States').should be_false }
47
+ it { subject.eu?(subject.find_by_name('Canada')).should be_false }
48
+ end
49
+
50
+ describe ".north_america?" do
51
+ it { subject.north_america?('Canada').should be_true }
52
+ it { subject.north_america?('United States').should be_true }
53
+ it { subject.north_america?(subject.find_by_name('United States')).should be_true }
54
+ it { subject.north_america?('United Kingdom').should be_false }
55
+ it { subject.north_america?(subject.find_by_name('France')).should be_false }
56
+ end
57
+
58
+ describe ".find_by_abbr" do
59
+ it { subject.find_by_abbr('USA')[:alpha3].should == 'USA' }
60
+ it { subject.find_by_abbr('US')[:alpha2].should == 'US' }
61
+ it { subject.find_by_abbr('ESP')[:alpha3].should == 'ESP' }
62
+ it { subject.find_by_abbr('ES')[:alpha2].should == 'ES' }
63
+ end
64
+
65
+ describe "regional shortcuts" do
66
+ it { subject.north_america.length.should == 3 }
67
+ it { subject.eu.length.should == 27 }
68
+ end
69
+
70
+ describe ".find_all_by_region" do
71
+ it { subject.find_all_by_region('North America').length.should == 3 }
72
+ it { subject.find_all_by_region('EU').length.should == 27 }
73
+ it { subject.find_all_by_region('Northern Hemisphere').length.should == 40 }
74
+ it { subject.find_all_by_region('Western Hemisphere').length.should == 8 }
75
+ end
76
+
77
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validatious::Addresses::States do
4
+
5
+ describe ".find_by_name" do
6
+ it "should return proper results" do
7
+ subject.find_by_name('Kansas')[:name].should == 'KANSAS'
8
+ subject.find_by_name('Washington')[:name].should == 'WASHINGTON'
9
+ subject.find_by_name('Arkansas')[:name].should == 'ARKANSAS'
10
+ end
11
+
12
+ it "should be case insensitive" do
13
+ subject.find_by_name('KaNSaS')[:name].should == 'KANSAS'
14
+ subject.find_by_name('ARKansAS')[:name].should == 'ARKANSAS'
15
+ subject.find_by_name('texAs')[:name].should == 'TEXAS'
16
+ end
17
+ end
18
+
19
+ describe ".find_by_abbr" do
20
+ it "should return proper results" do
21
+ subject.find_by_abbr('KS')[:name].should == 'KANSAS'
22
+ subject.find_by_abbr('AR')[:name].should == 'ARKANSAS'
23
+ subject.find_by_abbr('AK')[:name].should == 'ALASKA'
24
+ end
25
+ end
26
+
27
+ end
@@ -5,6 +5,7 @@ describe Validatious, 'HelperMethods' do
5
5
  it 'should define class validation methods' do
6
6
  Post.should respond_to(:validates_url_format_of)
7
7
  Post.should respond_to(:validates_email_format_of)
8
+ Post.should respond_to(:validates_postal_code_format_of)
8
9
  Post.should respond_to(:validates_text_content_of)
9
10
  end
10
11
 
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Validatious::Validators::PostalCodeValidator do
6
+
7
+ describe '12345' do
8
+ it "should be valid" do
9
+ Person.validates_postal_code_format_of(:postal_code, :country => ["US", 'CA'])
10
+ p = Person.new :postal_code => 10001
11
+ p.should be_valid
12
+ end
13
+ end
14
+
15
+ end
metadata CHANGED
@@ -1,50 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: validatious
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
4
5
  prerelease:
5
- version: 0.3.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Joel Moss
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-06 00:00:00 +01:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: activemodel
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70131390007220 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70131390007220
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70131390006740 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
36
33
  type: :development
37
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *70131390006740
38
36
  description: A collection of delicious Rails validators
39
- email:
37
+ email:
40
38
  - joel@developwithstyle.com
41
39
  executables: []
42
-
43
40
  extensions: []
44
-
45
41
  extra_rdoc_files: []
46
-
47
- files:
42
+ files:
48
43
  - .gitignore
49
44
  - .rspec
50
45
  - Gemfile
@@ -52,55 +47,64 @@ files:
52
47
  - README.md
53
48
  - Rakefile
54
49
  - lib/validatious.rb
50
+ - lib/validatious/addresses/countries.rb
51
+ - lib/validatious/addresses/provinces.rb
52
+ - lib/validatious/addresses/searchable.rb
53
+ - lib/validatious/addresses/states.rb
55
54
  - lib/validatious/helper_methods.rb
56
55
  - lib/validatious/locale/en.yml
57
56
  - lib/validatious/validators/email_validator.rb
57
+ - lib/validatious/validators/postal_code_validator.rb
58
58
  - lib/validatious/validators/text_content_validator.rb
59
59
  - lib/validatious/validators/url_validator.rb
60
60
  - lib/validatious/version.rb
61
61
  - spec/spec_helper.rb
62
62
  - spec/support/deferred_garbage_collection.rb
63
+ - spec/support/models/person.rb
63
64
  - spec/support/models/post.rb
64
65
  - spec/support/models/topic.rb
66
+ - spec/validatious/addresses/countries_spec.rb
67
+ - spec/validatious/addresses/states_spec.rb
65
68
  - spec/validatious/helper_methods_spec.rb
66
69
  - spec/validatious/validators/email_validator_spec.rb
70
+ - spec/validatious/validators/postal_code_validator_spec.rb
67
71
  - spec/validatious/validators/text_content_validator_spec.rb
68
72
  - spec/validatious/validators/url_validator_spec.rb
69
73
  - validatious.gemspec
70
- has_rdoc: true
71
74
  homepage: https://github.com/joelmoss/validatious
72
75
  licenses: []
73
-
74
76
  post_install_message:
75
77
  rdoc_options: []
76
-
77
- require_paths:
78
+ require_paths:
78
79
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
80
+ required_ruby_version: !ruby/object:Gem::Requirement
80
81
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "0"
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
91
92
  requirements: []
92
-
93
93
  rubyforge_project:
94
- rubygems_version: 1.3.9.1
94
+ rubygems_version: 1.8.15
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: A collection of delicious Rails validators
98
- test_files:
98
+ test_files:
99
99
  - spec/spec_helper.rb
100
100
  - spec/support/deferred_garbage_collection.rb
101
+ - spec/support/models/person.rb
101
102
  - spec/support/models/post.rb
102
103
  - spec/support/models/topic.rb
104
+ - spec/validatious/addresses/countries_spec.rb
105
+ - spec/validatious/addresses/states_spec.rb
103
106
  - spec/validatious/helper_methods_spec.rb
104
107
  - spec/validatious/validators/email_validator_spec.rb
108
+ - spec/validatious/validators/postal_code_validator_spec.rb
105
109
  - spec/validatious/validators/text_content_validator_spec.rb
106
110
  - spec/validatious/validators/url_validator_spec.rb