Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/string.rb

Constant Summary collapse

INT_STRING =

strings de cada classe de equivalência para testes

"3"
EMAIL_STRING =
"[email protected]"
FLOAT_STRING =
"3.14"
PHONE_STRING =
"(61) 98999-9999"
DATE_STRING =
"12/01/1997"
CUSTOM_METHODS =
%w(is_i? is_email? is_float? is_phone? is_date?)
EQUIVALENCE_CLASSES =
{
  "is_i?" => "INTEGER",
  "is_email?" => "EMAIL",
  "is_float?" => "FLOAT",
  "is_phone?" => "PHONE",
  "is_date?" => "DATE",
}
STRINGS_EQUIVALENCE_CLASSES =
{
    "is_i?" => String::INT_STRING,
    "is_email?" => String::EMAIL_STRING,
    "is_float?" => String::FLOAT_STRING,
    "is_phone?" => String::PHONE_STRING,
    "is_date?" => String::DATE_STRING,
}

Instance Method Summary collapse

Instance Method Details

#is_date?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ext/string.rb', line 44

def is_date?

end

#is_email?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ext/string.rb', line 31

def is_email?
  /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i === self
end

#is_float?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ext/string.rb', line 35

def is_float?
  self.to_f.to_s === self
end

#is_i?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ext/string.rb', line 27

def is_i?
  /\A[-+]?\d+\z/ === self
end

#is_phone?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/ext/string.rb', line 39

def is_phone?
  /^\([1-9]{2}\) (?:[2-8]|9[1-9])[0-9]{3}\-[0-9]{4}$/ === self ||
      /^\([1-9]{2}\)(?:[2-8]|9[1-9])[0-9]{3}\-[0-9]{4}$/ === self
end