Class: Active::Services::Validators

Inherits:
Object
  • Object
show all
Defined in:
lib/services/validators.rb

Constant Summary collapse

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" ],
  [ "Nevada", "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" ]
]

Class Method Summary collapse

Class Method Details

.addressObject



32
33
34
# File 'lib/services/validators.rb', line 32

def self.address
  false
end

.cityObject



28
29
30
# File 'lib/services/validators.rb', line 28

def self.city
  false
end

.email(arg) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/services/validators.rb', line 5

def self.email arg
  if (arg =~  /((\w|-)+(\.\w+)?)+@\w+\.\w+/) == nil  
  # if (arg =~  /^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/) == nil
    return false
  else
    return true
  end
end

.full_name(abbr) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/services/validators.rb', line 90

def self.full_name(abbr)
  STATES.find do |i|
    if i[1] == abbr.upcase
      return i[0]
    end
  end
  return nil
end

.stateObject



24
25
26
# File 'lib/services/validators.rb', line 24

def self.state
  true
end

.valid_state(name) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/services/validators.rb', line 99

def self.valid_state(name)
  return nil if name.nil?
  STATES.find do |i|
    if i[0].upcase==name.strip.upcase
      return i[0]
    elsif i[1] == name.upcase
      return i[0]
    end
  end
  return nil
end

.valid_zip(zip) ⇒ Object

NO MODIFYING IN A VALIDATION CLASS !! clean zip (geekswithblogs.net/MainaD/archive/2007/12/03/117321.aspx)



114
115
116
117
118
119
120
# File 'lib/services/validators.rb', line 114

def self.valid_zip(zip)
  if zip!="00000" && zip.to_s.strip=~/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/
    return zip.to_s.strip
  else
    return nil
  end
end

.zip(arg) ⇒ Object

return true or false very short check for 5 consecutive digits, no leading or trailing whitespace.



16
17
18
19
20
21
22
# File 'lib/services/validators.rb', line 16

def self.zip(arg)
  # if (arg =~ /\be(\w*)/) != -1
  #   true
  # else
  #   false
  # end
end