lib/validators/phony_validator.rb in phony_rails-0.6.0 vs lib/validators/phony_validator.rb in phony_rails-0.6.1
- old
+ new
@@ -6,24 +6,32 @@
# Validates a String using Phony.plausible? method.
def validate_each(record, attribute, value)
return if value.blank?
@record = record
- @record.errors.add(attribute, error_message) if not Phony.plausible?(value, cc: country_code_or_country_number)
+ @record.errors.add(attribute, error_message) if not Phony.plausible?(value, cc: country_number)
end
private
def error_message
options[:message] || :improbable_phone
end
- def country_code_or_country_number
- options[:country_code] || record_country_number || record_country_code
+ def country_number
+ options[:country_number] || record_country_number || country_number_from_country_code
end
def record_country_number
@record.country_number if @record.respond_to?(:country_number)
+ end
+
+ def country_number_from_country_code
+ PhonyRails.country_number_for(country_code)
+ end
+
+ def country_code
+ options[:country_code] || record_country_code
end
def record_country_code
@record.country_code if @record.respond_to?(:country_code)
end