Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extend_string.rb
Instance Method Summary collapse
-
#api_datetime? ⇒ Boolean
returns true if the string match with the regex of a datetime used in the BlackStack’s API.
-
#api_to_sql_datetime ⇒ Object
Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
-
#domain? ⇒ Boolean
returns true if the string match with the regex of a domain.
-
#email? ⇒ Boolean
returns true if the string match with the regex of an email.
-
#encode_html ⇒ Object
Escape the string to be shown into an HTML screen.
-
#encode_string ⇒ Object
Then it makes it compatible with UTF-8.
-
#escape_javascript ⇒ Object
Escapes carriage returns and single and double quotes for JavaScript segments.
-
#filename? ⇒ Boolean
returns true if the string match with the regex of a filename.
-
#fixnum? ⇒ Boolean
returns true if the string match with the regex of a number.
-
#guid? ⇒ Boolean
returns true if the string match with the regex of a GUID.
-
#mail_handler ⇒ Object
raise an exception if ‘email` is not a valid email address.
-
#password? ⇒ Boolean
returns true if the string meets all the security requirements for a password.
-
#personal_email? ⇒ Boolean
raise an exception if ‘email` is not a valid email address.
-
#phone? ⇒ Boolean
returns true if the string match with the regex of a phone number.
-
#spin ⇒ Object
Returns a random spin from a spintax.
- #spintax? ⇒ Boolean
- #sql_datetime? ⇒ Boolean
-
#sql_to_api_datetime ⇒ Object
Convierte un string con formato sql-datatime a un string con formato sql-datetime.
-
#to_guid ⇒ Object
Rewrite a GUID as a standard format.
-
#to_sql ⇒ Object
Escape simple-quotes too add the string into literal-string of a dynamic query build into the Ruby code.
-
#url? ⇒ Boolean
returns true if the string match with the regex of a URL.
Instance Method Details
#api_datetime? ⇒ Boolean
returns true if the string match with the regex of a datetime used in the BlackStack’s API
65 66 67 |
# File 'lib/extend_string.rb', line 65 def api_datetime? BlackStack::Strings::DateTime::datetime_api_check(self.to_s) end |
#api_to_sql_datetime ⇒ Object
Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
80 81 82 |
# File 'lib/extend_string.rb', line 80 def api_to_sql_datetime BlackStack::Strings::DateTime::datetime_api_to_sql(self.to_s) end |
#domain? ⇒ Boolean
returns true if the string match with the regex of a domain
41 42 43 44 |
# File 'lib/extend_string.rb', line 41 def domain? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_DOMAIN}$/ return false end |
#email? ⇒ Boolean
returns true if the string match with the regex of an email
21 22 23 24 |
# File 'lib/extend_string.rb', line 21 def email? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_EMAIL}$/ return false end |
#encode_html ⇒ Object
Escape the string to be shown into an HTML screen. Then it makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961
121 122 123 |
# File 'lib/extend_string.rb', line 121 def encode_html() BlackStack::Strings::Encoding::encode_html(self.to_s) end |
#encode_string ⇒ Object
Then it makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961
114 115 116 |
# File 'lib/extend_string.rb', line 114 def encode_string() BlackStack::Strings::Encoding::encode_string(self.to_s) end |
#escape_javascript ⇒ Object
Escapes carriage returns and single and double quotes for JavaScript segments. reference: api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html
Example: <% s = ‘Hello World!’ %> text = “<%=s.escape_javascript%>”
Never use single-quotation marks, because this method is not supporting it. <% s = ‘Hello World!’ %> text = ‘<%=s.escape_javascript%>’
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/extend_string.rb', line 140 def escape_javascript s = self.dup js_escape_map = { '\\' => '\\\\', "</" => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\'", "`" => "\`", "$" => "\\$", } js_escape_map.each { | x, y | s.gsub!(x,y) } s end |
#filename? ⇒ Boolean
returns true if the string match with the regex of a filename
15 16 17 18 |
# File 'lib/extend_string.rb', line 15 def filename? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FILENAME}$/ return false end |
#fixnum? ⇒ Boolean
returns true if the string match with the regex of a number
59 60 61 62 |
# File 'lib/extend_string.rb', line 59 def fixnum? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FIXNUM}$/ return false end |
#guid? ⇒ Boolean
returns true if the string match with the regex of a GUID
9 10 11 12 |
# File 'lib/extend_string.rb', line 9 def guid? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_GUID}$/ return false end |
#mail_handler ⇒ Object
raise an exception if ‘email` is not a valid email address. return an array with the companies who are hosting an email address, by running the linux command `host`.
34 35 36 |
# File 'lib/extend_string.rb', line 34 def mail_handler return BlackStack::Netting.getMailHandler(self.to_s) end |
#password? ⇒ Boolean
returns true if the string meets all the security requirements for a password
3 4 5 6 |
# File 'lib/extend_string.rb', line 3 def password? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PASSWORD}$/ return false end |
#personal_email? ⇒ Boolean
raise an exception if ‘email` is not a valid email address. return if the email domain is gmail, hotmail, outlook, yahoo, comcast, aol, msn or sbcglobal.
28 29 30 |
# File 'lib/extend_string.rb', line 28 def personal_email? return BlackStack::Netting.isPersonalEmail?(self.to_s) end |
#phone? ⇒ Boolean
returns true if the string match with the regex of a phone number
47 48 49 50 |
# File 'lib/extend_string.rb', line 47 def phone? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PHONE}$/ return false end |
#spin ⇒ Object
Returns a random spin from a spintax
108 109 110 |
# File 'lib/extend_string.rb', line 108 def spin BlackStack::Strings::Spinning::random_spinning_variation(self.to_s) end |
#spintax? ⇒ Boolean
97 98 99 |
# File 'lib/extend_string.rb', line 97 def spintax? BlackStack::Strings::Spinning::spintax?(self.to_s) end |
#sql_datetime? ⇒ Boolean
70 71 72 |
# File 'lib/extend_string.rb', line 70 def sql_datetime? BlackStack::Strings::DateTime::datetime_sql_check(self.to_s) end |
#sql_to_api_datetime ⇒ Object
Convierte un string con formato sql-datatime a un string con formato sql-datetime.
75 76 77 |
# File 'lib/extend_string.rb', line 75 def sql_to_api_datetime BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_s) end |
#to_guid ⇒ Object
Rewrite a GUID as a standard format. Example: 331a92c3-5fe1-47a2-a31b-cfa439b5b4f9 -> 331A92C3-5FE1-47A2-A31B-CFA439B5B4F9
86 87 88 |
# File 'lib/extend_string.rb', line 86 def to_guid BlackStack::Strings::Encoding::encode_guid(self.to_s) end |
#to_sql ⇒ Object
Escape simple-quotes too add the string into literal-string of a dynamic query build into the Ruby code. Example: “I’m BlackStack” -> “I”m BlackStack”
92 93 94 |
# File 'lib/extend_string.rb', line 92 def to_sql BlackStack::Strings::SQL::string_to_sql_string(self.to_s) end |
#url? ⇒ Boolean
returns true if the string match with the regex of a URL
53 54 55 56 |
# File 'lib/extend_string.rb', line 53 def url? return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_URL}$/ return false end |