Module: MoreCoreExtensions::StringFormats
- Defined in:
- lib/more_core_extensions/core_ext/string/formats.rb
Constant Summary collapse
- RE_EMAIL =
From: Regular Expression Cookbook: 4.1 Validate Email Addresses
%r{\A[\w!#$\%&'*+/=?`\{|\}~^-]+(?:\.[\w!#$\%&'*+/=?`\{|\}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\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_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
- #integer? ⇒ Boolean
- #ipaddress? ⇒ Boolean
- #ipv4? ⇒ Boolean
- #ipv6? ⇒ Boolean
Instance Method Details
#domain_name? ⇒ Boolean
11 12 13 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 11 def domain_name? !!(self =~ RE_DOMAINNAME) end |
#email? ⇒ Boolean
5 6 7 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 5 def email? !!(self =~ RE_EMAIL) end |
#guid? ⇒ Boolean
37 38 39 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 37 def guid? !!(self =~ RE_GUID) end |
#integer? ⇒ Boolean
32 33 34 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 32 def integer? !!(self =~ RE_INTEGER) end |
#ipaddress? ⇒ Boolean
27 28 29 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 27 def ipaddress? ipv4? || ipv6? end |
#ipv4? ⇒ Boolean
17 18 19 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 17 def ipv4? !!(self =~ RE_IPV4) end |
#ipv6? ⇒ Boolean
23 24 25 |
# File 'lib/more_core_extensions/core_ext/string/formats.rb', line 23 def ipv6? !!(self =~ RE_IPV6) end |