Module: Mbrao::ParserValidations::ClassMethods

Defined in:
lib/mbrao/parser_validations.rb

Overview

Class methods.

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) email?(text)

Checks if the text is a valid email.

Parameters:

  • text (String)

    The text to check.

Returns:

  • (Boolean)

    true if the string is valid email, false otherwise.



19
20
21
# 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

- (Boolean) url?(text)

Checks if the text is a valid URL.

Parameters:

  • text (String)

    The text to check.

Returns:

  • (Boolean)

    true if the string is valid URL, false otherwise.



27
28
29
30
31
32
33
34
35
36
37
38
# 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