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)


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_datetimeObject

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

Returns:

  • (Boolean)


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

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



121
122
123
# File 'lib/extend_string.rb', line 121

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



114
115
116
# File 'lib/extend_string.rb', line 114

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



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

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)


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

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

#mail_handlerObject

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

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

#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.

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

#spinObject

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

Returns:

  • (Boolean)


97
98
99
# File 'lib/extend_string.rb', line 97

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

#sql_datetime?Boolean

Returns:

  • (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_datetimeObject

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_guidObject

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_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”



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

Returns:

  • (Boolean)


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