Method: PureValidator::Validators::UrlValidator.validate

Defined in:
lib/pure_validator/validators/url_validator.rb

.validate(value, url_flag) ⇒ Array

Validates that string is a valid url

Parameters:

  • value (String)

    string to validate

  • url (Boolean)

    should given string be url or not

Returns:

  • (Array)

    empty array if number is valid, array of error messages otherwise



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pure_validator/validators/url_validator.rb', line 8

def self.validate(value, url_flag)
  return [] if value.nil?

  errors = []
  if url_flag
    errors << PureValidator::I18n.t('errors.invalid_url') unless !!URL_REGEXP.match(value)
  else
    errors << PureValidator::I18n.t('errors.can_not_be_url') if !!URL_REGEXP.match(value)
  end

  errors
end