blackstack-core 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/example01.rb +299 -299
- data/examples/example02.rb +3 -3
- data/lib/blackstack-core.rb +26 -26
- data/lib/extend_datetime.rb +5 -5
- data/lib/extend_exception.rb +10 -10
- data/lib/extend_fixnum.rb +14 -14
- data/lib/extend_float.rb +6 -6
- data/lib/extend_string.rb +143 -143
- data/lib/extend_time.rb +10 -10
- data/lib/functions.rb +829 -839
- metadata +6 -6
data/lib/extend_exception.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class Exception
|
2
|
-
def to_html(include_backtrace=true)
|
3
|
-
BlackStack::Strings::Encoding.encode_exception(self, include_backtrace)
|
4
|
-
end
|
5
|
-
|
6
|
-
def to_console(include_backtrace=true)
|
7
|
-
ret = self.to_s
|
8
|
-
ret += "\r\n" + self.backtrace.join("\r\n") if (include_backtrace == true)
|
9
|
-
ret
|
10
|
-
end # to_console
|
1
|
+
class Exception
|
2
|
+
def to_html(include_backtrace=true)
|
3
|
+
BlackStack::Strings::Encoding.encode_exception(self, include_backtrace)
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_console(include_backtrace=true)
|
7
|
+
ret = self.to_s
|
8
|
+
ret += "\r\n" + self.backtrace.join("\r\n") if (include_backtrace == true)
|
9
|
+
ret
|
10
|
+
end # to_console
|
11
11
|
end
|
data/lib/extend_fixnum.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
class Fixnum
|
2
|
-
# Converts number to a string with a format like xx,xxx,xxx.xxxx
|
3
|
-
def to_label()
|
4
|
-
BlackStack::Number::Encoding::format_with_separator(self)
|
5
|
-
end
|
6
|
-
|
7
|
-
# Convierte una cantidad de minutos a una leyenda legible por el usuario.
|
8
|
-
# Ejemplo: "2 days, 5 hours"
|
9
|
-
# Ejemplo: "4 hours, 30 minutes"
|
10
|
-
# Ejemplo: "3 days, 4 hour"
|
11
|
-
def to_time_spent()
|
12
|
-
BlackStack::Number::Encoding::encode_minutes(self)
|
13
|
-
end
|
14
|
-
end # class String
|
1
|
+
class Fixnum
|
2
|
+
# Converts number to a string with a format like xx,xxx,xxx.xxxx
|
3
|
+
def to_label()
|
4
|
+
BlackStack::Number::Encoding::format_with_separator(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
# Convierte una cantidad de minutos a una leyenda legible por el usuario.
|
8
|
+
# Ejemplo: "2 days, 5 hours"
|
9
|
+
# Ejemplo: "4 hours, 30 minutes"
|
10
|
+
# Ejemplo: "3 days, 4 hour"
|
11
|
+
def to_time_spent()
|
12
|
+
BlackStack::Number::Encoding::encode_minutes(self)
|
13
|
+
end
|
14
|
+
end # class String
|
data/lib/extend_float.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class Float
|
2
|
-
# Converts number to a string with a format like xx,xxx,xxx.xxxx
|
3
|
-
def to_label()
|
4
|
-
BlackStack::Number::Encoding::format_with_separator(self)
|
5
|
-
end
|
6
|
-
end # class String
|
1
|
+
class Float
|
2
|
+
# Converts number to a string with a format like xx,xxx,xxx.xxxx
|
3
|
+
def to_label()
|
4
|
+
BlackStack::Number::Encoding::format_with_separator(self)
|
5
|
+
end
|
6
|
+
end # class String
|
data/lib/extend_string.rb
CHANGED
@@ -1,143 +1,143 @@
|
|
1
|
-
class String
|
2
|
-
# returns true if the string meets all the security requirements for a password
|
3
|
-
def password?
|
4
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PASSWORD}$/
|
5
|
-
return false
|
6
|
-
end
|
7
|
-
|
8
|
-
# returns true if the string match with the regex of a GUID
|
9
|
-
def guid?
|
10
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_GUID}$/
|
11
|
-
return false
|
12
|
-
end
|
13
|
-
|
14
|
-
# returns true if the string match with the regex of a filename
|
15
|
-
def filename?
|
16
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FILENAME}$/
|
17
|
-
return false
|
18
|
-
end
|
19
|
-
|
20
|
-
# returns true if the string match with the regex of an email
|
21
|
-
def email?
|
22
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_EMAIL}$/
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
|
26
|
-
# returns true if the string match with the regex of a domain
|
27
|
-
def domain?
|
28
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_DOMAIN}$/
|
29
|
-
return false
|
30
|
-
end
|
31
|
-
|
32
|
-
# returns true if the string match with the regex of a phone number
|
33
|
-
def phone?
|
34
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PHONE}$/
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
|
38
|
-
# returns true if the string match with the regex of a URL
|
39
|
-
def url?
|
40
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_URL}$/
|
41
|
-
return false
|
42
|
-
end
|
43
|
-
|
44
|
-
# returns true if the string match with the regex of a number
|
45
|
-
def fixnum?
|
46
|
-
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FIXNUM}$/
|
47
|
-
return false
|
48
|
-
end
|
49
|
-
|
50
|
-
# returns true if the string match with the regex of a datetime used in the BlackStack's API
|
51
|
-
def api_datetime?
|
52
|
-
BlackStack::Strings::DateTime::datetime_api_check(self.to_s)
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
def sql_datetime?
|
57
|
-
BlackStack::Strings::DateTime::datetime_sql_check(self.to_s)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Convierte un string con formato sql-datatime a un string con formato sql-datetime.
|
61
|
-
def sql_to_api_datetime
|
62
|
-
BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_s)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
|
66
|
-
def api_to_sql_datetime
|
67
|
-
BlackStack::Strings::DateTime::datetime_api_to_sql(self.to_s)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Rewrite a GUID as a standard format.
|
71
|
-
# Example: {331a92c3-5fe1-47a2-a31b-cfa439b5b4f9} -> 331A92C3-5FE1-47A2-A31B-CFA439B5B4F9
|
72
|
-
def to_guid
|
73
|
-
BlackStack::Strings::Encoding::encode_guid(self.to_s)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Escape simple-quotes too add the string into literal-string of a dynamic query build into the Ruby code.
|
77
|
-
# Example: "I'm BlackStack" -> "I''m BlackStack"
|
78
|
-
def to_sql
|
79
|
-
BlackStack::Strings::SQL::string_to_sql_string(self.to_s)
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
def spintax?
|
84
|
-
BlackStack::Strings::Spinning::spintax?(self.to_s)
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
def spintax?
|
89
|
-
BlackStack::Strings::Spinning::valid_spinning_syntax?(self.to_s) &&
|
90
|
-
BlackStack::Strings::Spinning::spintax?(self.to_s)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns a random spin from a spintax
|
94
|
-
def spin
|
95
|
-
BlackStack::Strings::Spinning::random_spinning_variation(self.to_s)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Then it makes it compatible with UTF-8.
|
99
|
-
# More details here: https://bitbucket.org/leandro_sardi/blackstack/issues/961
|
100
|
-
def encode_string()
|
101
|
-
BlackStack::Strings::Encoding::encode_string(self.to_s)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Escape the string to be shown into an HTML screen.
|
105
|
-
# Then it makes it compatible with UTF-8.
|
106
|
-
# More details here: https://bitbucket.org/leandro_sardi/blackstack/issues/961
|
107
|
-
def encode_html()
|
108
|
-
BlackStack::Strings::Encoding::encode_html(self.to_s)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Escapes carriage returns and single and double quotes for JavaScript segments.
|
112
|
-
# reference: https://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html
|
113
|
-
#
|
114
|
-
# Example:
|
115
|
-
# <%
|
116
|
-
# s = 'Hello World!'
|
117
|
-
# %>
|
118
|
-
# text = "<%=s.escape_javascript%>"
|
119
|
-
#
|
120
|
-
# Never use single-quotation marks, because this method is not supporting it.
|
121
|
-
# <%
|
122
|
-
# s = 'Hello World!'
|
123
|
-
# %>
|
124
|
-
# text = '<%=s.escape_javascript%>'
|
125
|
-
#
|
126
|
-
def escape_javascript
|
127
|
-
s = self.dup
|
128
|
-
js_escape_map = {
|
129
|
-
'\\' => '\\\\',
|
130
|
-
"</" => '<\/',
|
131
|
-
"\r\n" => '\n',
|
132
|
-
"\n" => '\n',
|
133
|
-
"\r" => '\n',
|
134
|
-
'"' => '\\"',
|
135
|
-
"'" => "\'",
|
136
|
-
"`" => "\`",
|
137
|
-
"$" => "\\$",
|
138
|
-
}
|
139
|
-
js_escape_map.each { | x, y | s.gsub!(x,y) }
|
140
|
-
s
|
141
|
-
end
|
142
|
-
|
143
|
-
end # class String
|
1
|
+
class String
|
2
|
+
# returns true if the string meets all the security requirements for a password
|
3
|
+
def password?
|
4
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PASSWORD}$/
|
5
|
+
return false
|
6
|
+
end
|
7
|
+
|
8
|
+
# returns true if the string match with the regex of a GUID
|
9
|
+
def guid?
|
10
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_GUID}$/
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
|
14
|
+
# returns true if the string match with the regex of a filename
|
15
|
+
def filename?
|
16
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FILENAME}$/
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
|
20
|
+
# returns true if the string match with the regex of an email
|
21
|
+
def email?
|
22
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_EMAIL}$/
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns true if the string match with the regex of a domain
|
27
|
+
def domain?
|
28
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_DOMAIN}$/
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
|
32
|
+
# returns true if the string match with the regex of a phone number
|
33
|
+
def phone?
|
34
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_PHONE}$/
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
# returns true if the string match with the regex of a URL
|
39
|
+
def url?
|
40
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_URL}$/
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
# returns true if the string match with the regex of a number
|
45
|
+
def fixnum?
|
46
|
+
return true if self.to_s =~ /^#{BlackStack::Strings::MATCH_FIXNUM}$/
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
# returns true if the string match with the regex of a datetime used in the BlackStack's API
|
51
|
+
def api_datetime?
|
52
|
+
BlackStack::Strings::DateTime::datetime_api_check(self.to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
def sql_datetime?
|
57
|
+
BlackStack::Strings::DateTime::datetime_sql_check(self.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Convierte un string con formato sql-datatime a un string con formato sql-datetime.
|
61
|
+
def sql_to_api_datetime
|
62
|
+
BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
|
66
|
+
def api_to_sql_datetime
|
67
|
+
BlackStack::Strings::DateTime::datetime_api_to_sql(self.to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Rewrite a GUID as a standard format.
|
71
|
+
# Example: {331a92c3-5fe1-47a2-a31b-cfa439b5b4f9} -> 331A92C3-5FE1-47A2-A31B-CFA439B5B4F9
|
72
|
+
def to_guid
|
73
|
+
BlackStack::Strings::Encoding::encode_guid(self.to_s)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Escape simple-quotes too add the string into literal-string of a dynamic query build into the Ruby code.
|
77
|
+
# Example: "I'm BlackStack" -> "I''m BlackStack"
|
78
|
+
def to_sql
|
79
|
+
BlackStack::Strings::SQL::string_to_sql_string(self.to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
def spintax?
|
84
|
+
BlackStack::Strings::Spinning::spintax?(self.to_s)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
def spintax?
|
89
|
+
BlackStack::Strings::Spinning::valid_spinning_syntax?(self.to_s) &&
|
90
|
+
BlackStack::Strings::Spinning::spintax?(self.to_s)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns a random spin from a spintax
|
94
|
+
def spin
|
95
|
+
BlackStack::Strings::Spinning::random_spinning_variation(self.to_s)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Then it makes it compatible with UTF-8.
|
99
|
+
# More details here: https://bitbucket.org/leandro_sardi/blackstack/issues/961
|
100
|
+
def encode_string()
|
101
|
+
BlackStack::Strings::Encoding::encode_string(self.to_s)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Escape the string to be shown into an HTML screen.
|
105
|
+
# Then it makes it compatible with UTF-8.
|
106
|
+
# More details here: https://bitbucket.org/leandro_sardi/blackstack/issues/961
|
107
|
+
def encode_html()
|
108
|
+
BlackStack::Strings::Encoding::encode_html(self.to_s)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Escapes carriage returns and single and double quotes for JavaScript segments.
|
112
|
+
# reference: https://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html
|
113
|
+
#
|
114
|
+
# Example:
|
115
|
+
# <%
|
116
|
+
# s = 'Hello World!'
|
117
|
+
# %>
|
118
|
+
# text = "<%=s.escape_javascript%>"
|
119
|
+
#
|
120
|
+
# Never use single-quotation marks, because this method is not supporting it.
|
121
|
+
# <%
|
122
|
+
# s = 'Hello World!'
|
123
|
+
# %>
|
124
|
+
# text = '<%=s.escape_javascript%>'
|
125
|
+
#
|
126
|
+
def escape_javascript
|
127
|
+
s = self.dup
|
128
|
+
js_escape_map = {
|
129
|
+
'\\' => '\\\\',
|
130
|
+
"</" => '<\/',
|
131
|
+
"\r\n" => '\n',
|
132
|
+
"\n" => '\n',
|
133
|
+
"\r" => '\n',
|
134
|
+
'"' => '\\"',
|
135
|
+
"'" => "\'",
|
136
|
+
"`" => "\`",
|
137
|
+
"$" => "\\$",
|
138
|
+
}
|
139
|
+
js_escape_map.each { | x, y | s.gsub!(x,y) }
|
140
|
+
s
|
141
|
+
end
|
142
|
+
|
143
|
+
end # class String
|
data/lib/extend_time.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class Time
|
2
|
-
# Converts a time object to an SQL friendy string: YYYY-MM-DD HH:mm:ss
|
3
|
-
def to_sql()
|
4
|
-
BlackStack::DateTime::Encoding::datetime_to_sql(self)
|
5
|
-
end
|
6
|
-
|
7
|
-
# Converts a time object to an API friendy string: YYYYMMDDHHmmss
|
8
|
-
def to_api()
|
9
|
-
BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_sql)
|
10
|
-
end
|
1
|
+
class Time
|
2
|
+
# Converts a time object to an SQL friendy string: YYYY-MM-DD HH:mm:ss
|
3
|
+
def to_sql()
|
4
|
+
BlackStack::DateTime::Encoding::datetime_to_sql(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
# Converts a time object to an API friendy string: YYYYMMDDHHmmss
|
8
|
+
def to_api()
|
9
|
+
BlackStack::Strings::DateTime::datetime_sql_to_api(self.to_sql)
|
10
|
+
end
|
11
11
|
end # class DateTime
|