This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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