Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mistergibson
Created January 16, 2018 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistergibson/d33f4154755c7bd5498f9fc464e9d290 to your computer and use it in GitHub Desktop.
Save mistergibson/d33f4154755c7bd5498f9fc464e9d290 to your computer and use it in GitHub Desktop.
class String
#
def valid_date?()
# Match for Date pattern
if (/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/.match(self))
true
else
false
end
end
#
def valid_datetime?()
# Match for ISO 8601 pattern
if (/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9][+-][0-9][0-9]:[0-9][0-9]/.match(self))
true
else
false
end
end
#
def valid_datetime_nolocale?()
# Match for not-so-much ISO 8601-ish pattern
if (/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/.match(self))
true
else
false
end
end
#
def valid_path?()
if (/.*(?:\\|\/)(.+)$/.match(self) || (self.split(" ").size == 1 || self.split("/").size > 1 || self == "/"))
true
else
false
end
end
#
def valid_jid?()
if /^(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?$/.match(self)
true
else
false
end
end
#
def camel_case?()
# self.match(/([A-Z][a-z]+[A-Z][a-zA-Z]+)/)
if self.match(/[A-Z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*/)
true
else
false
end
end
#
def split_camelcase()
if self.camel_case?()
self.split(/(?=[A-Z])/)
else
self
end
end
#
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment