Class: LIVR::Rules::Special::Url

Inherits:
LIVR::Rule show all
Defined in:
lib/livr/rules/special.rb

Constant Summary collapse

URL_RE_STR =
'^(?:(?:http|https)://)(?:\\S+(?::\\S*)[email protected])?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[0-1]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))\\.?|localhost)(?::\\d{2,5})?(?:[/?#]\\S*)?$'
URL_RE =
Regexp.compile(URL_RE_STR, "i")
MAX_URL_LENGTH =
2083

Instance Method Summary collapse

Methods inherited from LIVR::Rule

#initialize

Constructor Details

This class inherits a constructor from LIVR::Rule

Instance Method Details

#call(value, user_data, field_results) ⇒ Object


37
38
39
40
41
42
43
44
45
46
# File 'lib/livr/rules/special.rb', line 37

def call(value, user_data, field_results)
  return if is_no_value(value)
  return 'FORMAT_ERROR' if !is_primitive(value)

  if value.length < MAX_URL_LENGTH && URL_RE.match(value)
    return
  else
    'WRONG_URL'
  end
end