Class: Cregexp
- Inherits:
-
Object
- Object
- Cregexp
- Defined in:
- lib/cregexp.rb
Class Method Summary collapse
- .email(options = {}) ⇒ Object
-
.hex(options = {}) ⇒ Object
Hex Value #a3c113 passes #4d82h4 failes(contains h).
-
.image ⇒ Object
Image Checke if file extension is of a valid image type.
-
.ip(options = {}) ⇒ Object
IP Address.
-
.match(string, matcher, options = {}) ⇒ Object
Cregexp.match(“www.google.com”, :url) => true.
-
.slug(options = {}) ⇒ Object
Slug my-title-here passes my_title_here fails.
- .url(options = {}) ⇒ Object
Class Method Details
.email(options = {}) ⇒ Object
6 7 8 |
# File 'lib/cregexp.rb', line 6 def self.email( = {}) /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i end |
.hex(options = {}) ⇒ Object
Hex Value #a3c113 passes #4d82h4 failes(contains h)
25 26 27 |
# File 'lib/cregexp.rb', line 25 def self.hex( = {}) /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ end |
.image ⇒ Object
Image Checke if file extension is of a valid image type
31 32 33 |
# File 'lib/cregexp.rb', line 31 def self.image /.png|.jpg|.jpeg|.gif|.bmp|.tiff|.PNG|.JPG|.JPEG|.GIF|.BMP|.TIFF$/ end |
.ip(options = {}) ⇒ Object
IP Address
18 19 20 |
# File 'lib/cregexp.rb', line 18 def self.ip( = {}) /^(?:(?: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]?)$/ end |
.match(string, matcher, options = {}) ⇒ Object
Cregexp.match(“www.google.com”, :url) => true
36 37 38 |
# File 'lib/cregexp.rb', line 36 def self.match(string, matcher, = {}) !(string =~ send(matcher.to_sym)).nil? end |
.slug(options = {}) ⇒ Object
Slug my-title-here passes my_title_here fails
13 14 15 |
# File 'lib/cregexp.rb', line 13 def self.slug( = {}) /^[a-z0-9-]+$/ end |
.url(options = {}) ⇒ Object
2 3 4 |
# File 'lib/cregexp.rb', line 2 def self.url( = {}) /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix end |