blackstack-core 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7efdde4423249a891ed69c8536964164a3c1a5beae6702c2a8f9934fea8621d3
4
+ data.tar.gz: 716de4195b3455be7be4bfbe015a3377eb5aa64363244401e66560a2e82a0094
5
+ SHA512:
6
+ metadata.gz: 81d3a16c625325255e499cf65f493960c98fc55aa342526674568c1295eb93a15c9b7634a592dfdbec54bc650b1947ad55c926f6c14e7651297b8a9537002720
7
+ data.tar.gz: 6b838f8b586488013f4d50c059f96f98ae147b374579271beeb4c4ca32379f7d9ff1c3558428dd3d6bb0d1bcacc6f75cd1fb75c60cfc2e3d377146c6267c2502
@@ -0,0 +1,300 @@
1
+ require_relative '../lib/blackstack-core'
2
+
3
+ # returns true if the string meets all the security requirements for a password
4
+ puts ""
5
+ puts "Passwords"
6
+ a = ['Hello', 'HelloWorld12$3']
7
+ a.each { |s|
8
+ print "'#{s}'.password?... "
9
+ puts s.password?.to_s
10
+ }
11
+
12
+ # returns true if the string match with the regex of a GUID
13
+ puts ""
14
+ puts "GUIDs"
15
+ a = [
16
+ '{{331a92c3-5fe1-47a2-a31b-cfa439b5b4f9}',
17
+ '{331a92c3-5fe1-47a2-a31b-cfa439b5b4f9}',
18
+ '331a92c3-5fe1-47a2-a31b-cfa439b5b4f9',
19
+ '{331A92C3-5FE1-47A2-A31B-CFA439B5B4F9}',
20
+ '{331A92C3-5FE1-47A2-A31B-CFA439B5B4F9}}',
21
+ '331A92C3-5FE1-47A2-A31B-CFA439B5B4F9',
22
+ '331A92C3-5FE1-47A2-A31B-CFA439B5B4F9-fgf',
23
+ '331A92C35FE147A2A31BCFA439B5B4F9',
24
+ ]
25
+ a.each { |s|
26
+ print "'#{s}'.guid?... "
27
+ puts s.guid?.to_s
28
+ }
29
+
30
+ # returns true if the string match with the regex of a filename
31
+ puts ""
32
+ puts "Filenames"
33
+ a = [
34
+ 'c:\filename.txt',
35
+ 'c:/filename.txt',
36
+ 'filename_1.txt',
37
+ 'filename-1.txt',
38
+ 'filename+1.txt',
39
+ 'filename?1.txt',
40
+ 'filename*1.txt',
41
+ 'filename.txt',
42
+ 'filename',
43
+ 'filename.txt.rar',
44
+ ]
45
+ a.each { |s|
46
+ print "'#{s}'.filename?... "
47
+ puts s.filename?.to_s
48
+ }
49
+
50
+ # returns true if the string match with the regex of an email
51
+ puts ""
52
+ puts "Emails"
53
+ a = [
54
+ 'tango@expandedventure.com',
55
+ 'tango@expandedventure.com.ar',
56
+ 'tango',
57
+ 'tango@',
58
+ ]
59
+ a.each { |s|
60
+ print "'#{s}'.email?... "
61
+ puts s.email?.to_s
62
+ }
63
+
64
+ # returns true if the string match with the regex of a domain
65
+ puts ""
66
+ puts "Domains"
67
+ a = [
68
+ 'tango',
69
+ 'tango@expandedventure',
70
+ 'tango@expandedventure.com',
71
+ 'tango@expandedventure.com.ar',
72
+ 'expandedventure.com',
73
+ 'expandedventure.com.ar',
74
+ 'https://expandedventure.com.ar',
75
+ 'www.expandedventure.com.ar',
76
+ 'https://www.expandedventure.com.ar',
77
+ ]
78
+ a.each { |s|
79
+ print "'#{s}'.domain?... "
80
+ puts s.domain?.to_s
81
+ }
82
+
83
+ # returns true if the string match with the regex of a phone number
84
+ puts ""
85
+ puts "Domains"
86
+ a = [
87
+ '+54 9 11 5061 2148',
88
+ '545-5561-2148',
89
+ '545-561-2148',
90
+ '545 561 2148',
91
+ '54 545 561 2148',
92
+ '+54 545 561 2148',
93
+ '+54 545-561-2148',
94
+ '+54-545-561-2148',
95
+ ]
96
+ a.each { |s|
97
+ print "'#{s}'.domain?... "
98
+ puts s.phone?.to_s
99
+ }
100
+
101
+ # returns true if the string match with the regex of a URL
102
+ puts ""
103
+ puts "URLs"
104
+ a = [
105
+ 'tango',
106
+ 'tango@expandedventure',
107
+ 'tango@expandedventure.com',
108
+ 'tango@expandedventure.com.ar',
109
+ 'expandedventure.com',
110
+ 'expandedventure.com.ar',
111
+ 'https://expandedventure.com.ar',
112
+ 'www.expandedventure.com.ar',
113
+ 'https://www.expandedventure.com.ar',
114
+ ]
115
+ a.each { |s|
116
+ print "'#{s}'.url?... "
117
+ puts s.url?.to_s
118
+ }
119
+
120
+ # returns true if the string match with the regex of a number
121
+ puts ""
122
+ puts "Fixnums"
123
+ a = [
124
+ '5',
125
+ '5.5',
126
+ '5,5',
127
+ '5000',
128
+ '5,000',
129
+ '5.000',
130
+ ]
131
+ a.each { |s|
132
+ print "'#{s.to_s}'.fixnum?... "
133
+ puts s.fixnum?.to_s
134
+ }
135
+
136
+ # returns true if the string match with the regex of a datetime used in the BlackStack's API
137
+ puts ""
138
+ puts "SQL DateTimes"
139
+ a = [
140
+ '20191106215030',
141
+ '20191106',
142
+ '2019-11-06',
143
+ '2019-11-06 21:50:30',
144
+ '2019-13-06 21:50:30', # invalid month
145
+ '2019-11-06 25:50:30', # invalid hour
146
+ '2019-11-06 21:70:30', # invalid minute
147
+ '2019-11-06 21:50:70', # invalid second
148
+ ]
149
+ a.each { |s|
150
+ print "'#{s.to_s}'.sql_datetime?... "
151
+ puts s.sql_datetime?.to_s
152
+ }
153
+
154
+ #
155
+ puts ""
156
+ puts "API DateTimes"
157
+ a = [
158
+ '20191106215030',
159
+ '20191106',
160
+ '2019-11-06',
161
+ '2019-11-06 21:50:30',
162
+ '20191306215030', # invalid month
163
+ '20191106255030', # invalid hour
164
+ '20191106217030', # invalid minute
165
+ '20191106215070', # invalid second
166
+ ]
167
+ a.each { |s|
168
+ print "'#{s.to_s}'.api_datetime?... "
169
+ puts s.api_datetime?.to_s
170
+ }
171
+
172
+ # Convierte un string con formato sql-datatime a un string con formato sql-datetime.
173
+ puts ""
174
+ puts "SQL DateTime -> API DateTime"
175
+ a = [
176
+ '2019-11-06 21:50:30',
177
+ ]
178
+ a.each { |s|
179
+ print "'#{s.to_s}'.sql_to_api_datetime... "
180
+ puts s.sql_to_api_datetime.to_s
181
+ }
182
+
183
+ # Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
184
+ puts ""
185
+ puts "API DateTime -> SQL DateTime"
186
+ a = [
187
+ '20191106215030',
188
+ ]
189
+ a.each { |s|
190
+ print "'#{s.to_s}'.api_to_sql_datetime... "
191
+ puts s.api_to_sql_datetime.to_s
192
+ }
193
+
194
+ # Rewrite a GUID as a standard (normalized) format.
195
+ puts ""
196
+ puts "Any GUID -> Normalized Guid"
197
+ a = [
198
+ '{331a92c3-5fe1-47a2-a31b-cfa439b5b4f9}',
199
+ '331a92c3-5fe1-47a2-a31b-cfa439b5b4f9',
200
+ '{331A92C3-5FE1-47A2-A31B-CFA439B5B4F9}',
201
+ '331A92C3-5FE1-47A2-A31B-CFA439B5B4F9',
202
+ ]
203
+ a.each { |s|
204
+ print "'#{s}'.to_guid... "
205
+ puts s.to_guid.to_s
206
+ }
207
+
208
+ # Escape simple-quotes too add the string into literal-string of a dynamic query build into the Ruby code.
209
+ # Example: "I'm BlackStack" -> "I''m BlackStack"
210
+ puts ""
211
+ puts "Any String -> String with Escaped Quotes"
212
+ a = [
213
+ "I'm BlackStack",
214
+ "Hello World!",
215
+ ]
216
+ a.each { |s|
217
+ print "'#{s}'.to_sql... "
218
+ puts s.to_sql.to_s
219
+ }
220
+
221
+ #
222
+ puts ""
223
+ puts "Spintax"
224
+ a = [
225
+ "I'm BlackStack",
226
+ "Hello World!",
227
+ "{Hello|Hi} World!",
228
+ "{Hello|Hi|Good {Morning|Afternoon}} World!", # Nexted spintax. Not supported.
229
+ "{Hello|Hi World!", # wrong syntax.
230
+ ]
231
+ a.each { |s|
232
+ print "'#{s}'.spintax?... "
233
+ puts s.spintax?.to_s
234
+ }
235
+
236
+ # Returns a random spin from a spintax
237
+ puts ""
238
+ puts "Spin"
239
+ a = [
240
+ "{Hello|Hi|Good Morning|Good Afternoon} World!",
241
+ "{Hello|Hi|Good Morning|Good Afternoon} World!",
242
+ "{Hello|Hi|Good Morning|Good Afternoon} World!",
243
+ "{Hello|Hi|Good Morning|Good Afternoon} World!",
244
+ ]
245
+ a.each { |s|
246
+ print "'#{s}'.spin... "
247
+ puts s.spin
248
+ }
249
+
250
+ # Converts a time object to an SQL friendy string
251
+ puts ""
252
+ puts "Time object -> SQL"
253
+ a = [
254
+ Time.new(2019,11,6,15,25,55),
255
+ DateTime.new(2019,11,6,15,25,55),
256
+ ]
257
+ a.each { |o|
258
+ print "'#{o.to_s}'.to_sql... "
259
+ puts o.to_sql
260
+ }
261
+
262
+ # Converts number to a string with a format like xx,xxx,xxx.xxxx
263
+ puts ""
264
+ puts "Fixnum & Floats -> Screen Friendly Text"
265
+ a = [
266
+ 64443,
267
+ 64443.5454,
268
+ ]
269
+ a.each { |i|
270
+ print "'#{i.to_s}'.to_label... "
271
+ puts i.to_label
272
+ }
273
+
274
+ # Converts number to a string with a format like xx,xxx,xxx.xxxx
275
+ puts ""
276
+ puts "Fixnum Minutes -> Time Spent (days, hours, minutes)"
277
+ a = [
278
+ 59,
279
+ 60,
280
+ 61,
281
+ 600,
282
+ 601,
283
+ 1440,
284
+ 1441,
285
+ 1500,
286
+ 1501,
287
+ ]
288
+ a.each { |i|
289
+ print "Minutes '#{i.to_s}'.to_time_spent... "
290
+ puts i.to_time_spent
291
+ }
292
+
293
+
294
+ =begin # TODO: Pending
295
+ encode_string
296
+ encode_html
297
+ encode_exception
298
+ encode_period
299
+ encode_javascript
300
+ =end
@@ -0,0 +1,3 @@
1
+ require_relative '../lib/blackstack-core'
2
+
3
+ BlackStack::Netting::api_call('https://connectionsphere.com/api1.3/pampa/ping.json')
@@ -0,0 +1,26 @@
1
+ require 'pry'
2
+ require 'content_spinning'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'openssl'
7
+ require 'time'
8
+ =begin
9
+ require 'html_to_plain_text'
10
+ require "RedCloth"
11
+ require 'cgi'
12
+ require 'httpclient'
13
+ require 'open-uri'
14
+ require 'date'
15
+ require 'rest-client'
16
+ require 'net/ssh'
17
+ require 'digest/md5'
18
+ require 'domainatrix'
19
+ =end
20
+ require_relative './functions'
21
+ require_relative './extend_string'
22
+ require_relative './extend_time'
23
+ require_relative './extend_datetime'
24
+ require_relative './extend_fixnum'
25
+ require_relative './extend_float'
26
+ require_relative './extend_exception'
@@ -0,0 +1,6 @@
1
+ class DateTime
2
+ # Converts a time object to an SQL friendy string
3
+ def to_sql()
4
+ BlackStack::DateTime::Encoding::datetime_to_sql(self)
5
+ end
6
+ end # class DateTime
@@ -0,0 +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
11
+ end
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
11
+ end # class DateTime