Class: Worldwide::AddressValidator
- Inherits:
-
Object
- Object
- Worldwide::AddressValidator
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/worldwide/address_validator.rb
Instance Method Summary collapse
-
#errors(address) ⇒ Object
Return an array of diagnostics about the validity of this address.
-
#valid?(address) ⇒ Boolean
Return true if (as far as we know) the address is valid.
Instance Method Details
#errors(address) ⇒ Object
Return an array of diagnostics about the validity of this address. If no problems are found, then the result will be an empty array.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/worldwide/address_validator.rb', line 17 def errors(address) return [:address, :nil] if address.nil? result = [] normalized_address = address.normalize(autocorrect_level: 0) result << country_errors(normalized_address) result << province_errors(normalized_address) result << zip_errors(normalized_address) result << phone_errors(normalized_address) result << city_errors(normalized_address) result.reject(&:empty?) end |
#valid?(address) ⇒ Boolean
Return true if (as far as we know) the address is valid. Return false if we know of at least one error with the address.
34 35 36 37 38 |
# File 'lib/worldwide/address_validator.rb', line 34 def valid?(address) return false if address.nil? errors(address).empty? end |