Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/extend_string.rb

Instance Method Summary collapse

Instance Method Details

#api_datetime?Boolean

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

Returns:

  • (Boolean)


51
52
53
# File 'lib/extend_string.rb', line 51

def api_datetime?
  BlackStack::Strings::DateTime::datetime_api_check(self.to_s)        
end

#api_to_sql_datetimeObject

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



66
67
68
# File 'lib/extend_string.rb', line 66

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

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/extend_string.rb', line 27

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

Returns:

  • (Boolean)


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_htmlObject

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



107
108
109
# File 'lib/extend_string.rb', line 107

def encode_html()
  BlackStack::Strings::Encoding::encode_html(self.to_s)    
end

#encode_stringObject

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



100
101
102
# File 'lib/extend_string.rb', line 100

def encode_string()
  BlackStack::Strings::Encoding::encode_string(self.to_s)
end

#escape_javascriptObject

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



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# 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?Boolean

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/extend_string.rb', line 45

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

Returns:

  • (Boolean)


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

#password?Boolean

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

Returns:

  • (Boolean)


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

#phone?Boolean

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

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/extend_string.rb', line 33

def phone?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PHONE}$/
  return false
end

#spinObject

Returns a random spin from a spintax



94
95
96
# File 'lib/extend_string.rb', line 94

def spin
  BlackStack::Strings::Spinning::random_spinning_variation(self.to_s)
end

#spintax?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/extend_string.rb', line 83

def spintax?
  BlackStack::Strings::Spinning::spintax?(self.to_s)
end

#sql_datetime?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/extend_string.rb', line 56

def sql_datetime?
  BlackStack::Strings::DateTime::datetime_sql_check(self.to_s)            
end

#sql_to_api_datetimeObject

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



61
62
63
# File 'lib/extend_string.rb', line 61

def sql_to_api_datetime
  BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_s)    
end

#to_guidObject

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



72
73
74
# File 'lib/extend_string.rb', line 72

def to_guid
  BlackStack::Strings::Encoding::encode_guid(self.to_s)
end

#to_sqlObject

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”



78
79
80
# File 'lib/extend_string.rb', line 78

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

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/extend_string.rb', line 39

def url?
  return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_URL}$/
  return false
end