module Mbrao::ParserValidations::ClassMethods

Class methods.

Public Instance Methods

email?(text) click to toggle source

Checks if the text is a valid email.

@param text [String] The text to check. @return [Boolean] `true` if the string is valid email, `false` otherwise.

# File lib/mbrao/parser_validations.rb, line 19
def email?(text)
  /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i.match(text.ensure_string.strip)
end
url?(text) click to toggle source

Checks if the text is a valid URL.

@param text [String] The text to check. @return [Boolean] `true` if the string is valid URL, `false` otherwise.

# File lib/mbrao/parser_validations.rb, line 27
def url?(text)
  %r{
    ^(
      ([a-z0-9\-]+:\/\/) #PROTOCOL
      (([\w-]+\.)?) # LOWEST TLD
      ([\w-]+) # 2nd LEVEL TLD
      (\.[a-z]+) # TOP TLD
      ((:\d+)?) # PORT
      ([\S|\?]*) # PATH, QUERYSTRING AND FRAGMENT
    )$
  }ix.match(text.ensure_string.strip)
end