Module: MoreCoreExtensions::StringFormats
- Defined in:
- lib/more_core_extensions/core_ext/string/formats.rb
Constant Summary collapse
- RE_EMAIL =
%r{\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z}i
- RE_DOMAINNAME =
From: Regular Expression Cookbook: 7.15 Validating Domain Names
%r{^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$}i
- RE_HOSTNAME =
Based on RFC 1034
%r{^((?![0-9]*$)+(?![0-9]*\.))(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$}i
- RE_IPV4 =
From: Regular Expression Cookbook: 7.16 Matching IPv4 Addresses
%r{^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$}
- RE_IPV6 =
From: Regular Expression Cookbook: 7.17 Matching IPv6 Addresses
%r{^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}$)(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:))(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}$)(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:))$}i
- RE_INTEGER =
%r{^-?[0-9]+$}
- RE_GUID =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
Instance Method Summary collapse
- #domain_name? ⇒ Boolean
- #email? ⇒ Boolean
- #guid? ⇒ Boolean
- #hostname? ⇒ Boolean
- #integer? ⇒ Boolean
- #ipaddress? ⇒ Boolean
- #ipv4? ⇒ Boolean
- #ipv6? ⇒ Boolean
Instance Method Details
#domain_name? ⇒ Boolean
12 13 14 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 12 def domain_name? !!(self =~ RE_DOMAINNAME) end |
#email? ⇒ Boolean
6 7 8 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 6 def email? !!(self =~ RE_EMAIL) end |
#guid? ⇒ Boolean
44 45 46 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 44 def guid? !!(self =~ RE_GUID) end |
#hostname? ⇒ Boolean
18 19 20 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 18 def hostname? !!(self =~ RE_HOSTNAME) end |
#integer? ⇒ Boolean
39 40 41 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 39 def integer? !!(self =~ RE_INTEGER) end |
#ipaddress? ⇒ Boolean
34 35 36 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 34 def ipaddress? ipv4? || ipv6? end |
#ipv4? ⇒ Boolean
24 25 26 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 24 def ipv4? !!(self =~ RE_IPV4) end |
#ipv6? ⇒ Boolean
30 31 32 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 30 def ipv6? !!(self =~ RE_IPV6) end |