forked from jeremiahishere/format_validators
/
florida_counties_validator.rb
87 lines (84 loc) · 1.7 KB
/
florida_counties_validator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# counties use abbreviations and will not validate otherwise
# example: Saint Lucie must be St. Lucie
class FloridaCountiesValidator < ActiveModel::EachValidator
def validate_each record, attribute, value
value = value.downcase.split(' ').map {|w| w.capitalize }.join(' ')
# this part has not been tested
if value.include?("County")
message = value + ' should not contain the word county.'
record.errors[attribute] << (options[:message] || message )
value = value.gsub("County", "").strip
end
message = value + ' is not a county in Florida'
record.errors[attribute] << (options[:message] || message ) unless COUNTIES.include? value
end
COUNTIES = [
"Alachua",
"Baker",
"Bay",
"Bradford",
"Brevard",
"Broward",
"Calhoun",
"Charlotte",
"Citrus",
"Clay",
"Collier",
"Columbia",
"De Soto",
"Suncoast",
"Dixie",
"Duval",
"Escambia",
"Flagler",
"Franklin",
"Gadsden",
"Gilchrist",
"Glades",
"Gulf",
"Hamilton",
"Hardee",
"Hendry",
"Hernando",
"Highlands",
"Hillsborough Suncoast",
"Holmes",
"Indian River",
"Jackson",
"Jefferson",
"Lafayette",
"Lake",
"Lee",
"Leon",
"Levy",
"Liberty",
"Madison",
"Manatee",
"Marion",
"Martin",
"Miami-Dade",
"Monroe",
"Nassau",
"Okaloosa",
"Okeechobee",
"Orange",
"Osceloa",
"Palm Beach",
"Pasco",
"Pinellas",
"Polk",
"Putnam",
"Santa Rosa",
"Sarasota",
"Seminole",
"St. Johns",
"St. Lucie",
"Sumter",
"Suwannee",
"Taylor",
"Union",
"Volusia",
"Wakulla",
"Walton",
"Washington"]
end