class String

Public Instance Methods

api_datetime?() click to toggle source

returns true if the string match with the regex of a datetime used in the BlackStack's API

# File lib/extend_string.rb, line 51
def api_datetime?
  BlackStack::Strings::DateTime::datetime_api_check(self.to_s)        
end
api_to_sql_datetime() click to toggle source

Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).

# File lib/extend_string.rb, line 66
def api_to_sql_datetime
  BlackStack::Strings::DateTime::datetime_api_to_sql(self.to_s)
end
domain?() click to toggle source

returns true if the string match with the regex of a domain

# File lib/extend_string.rb, line 27
def domain?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_DOMAIN}$/  
  return false
end
email?() click to toggle source

returns true if the string match with the regex of an email

# File lib/extend_string.rb, line 21
def email?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_EMAIL}$/
  return false
end
encode_html() click to toggle source

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

# File lib/extend_string.rb, line 107
def encode_html()
  BlackStack::Strings::Encoding::encode_html(self.to_s)    
end
encode_string() click to toggle source

Then it makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961

# File lib/extend_string.rb, line 100
def encode_string()
  BlackStack::Strings::Encoding::encode_string(self.to_s)
end
escape_javascript() click to toggle source

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%>'

# File lib/extend_string.rb, line 126
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?() click to toggle source

returns true if the string match with the regex of a filename

# File lib/extend_string.rb, line 15
def filename?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FILENAME}$/
  return false
end
fixnum?() click to toggle source

returns true if the string match with the regex of a number

# File lib/extend_string.rb, line 45
def fixnum?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FIXNUM}$/    
  return false
end
guid?() click to toggle source

returns true if the string match with the regex of a GUID

# File lib/extend_string.rb, line 9
def guid?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_GUID}$/
  return false
end
password?() click to toggle source

returns true if the string meets all the security requirements for a password

# File lib/extend_string.rb, line 3
def password?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PASSWORD}$/
  return false
end
phone?() click to toggle source

returns true if the string match with the regex of a phone number

# File lib/extend_string.rb, line 33
def phone?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PHONE}$/
  return false
end
spin() click to toggle source

Returns a random spin from a spintax

# File lib/extend_string.rb, line 94
def spin
  BlackStack::Strings::Spinning::random_spinning_variation(self.to_s)
end
spintax?() click to toggle source
# File lib/extend_string.rb, line 83
def spintax?
  BlackStack::Strings::Spinning::spintax?(self.to_s)
end
sql_datetime?() click to toggle source
# File lib/extend_string.rb, line 56
def sql_datetime?
  BlackStack::Strings::DateTime::datetime_sql_check(self.to_s)            
end
sql_to_api_datetime() click to toggle source

Convierte un string con formato sql-datatime a un string con formato sql-datetime.

# File lib/extend_string.rb, line 61
def sql_to_api_datetime
  BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_s)    
end
to_guid() click to toggle source

Rewrite a GUID as a standard format. Example: {331a92c3-5fe1-47a2-a31b-cfa439b5b4f9} -> 331A92C3-5FE1-47A2-A31B-CFA439B5B4F9

# File lib/extend_string.rb, line 72
def to_guid
  BlackStack::Strings::Encoding::encode_guid(self.to_s)
end
to_sql() click to toggle source

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”

# File lib/extend_string.rb, line 78
def to_sql
  BlackStack::Strings::SQL::string_to_sql_string(self.to_s)
end
url?() click to toggle source

returns true if the string match with the regex of a URL

# File lib/extend_string.rb, line 39
def url?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_URL}$/
  return false
end