Module: Gloo::Objs::StringMsgs
Instance Method Summary collapse
-
#msg_count_chars ⇒ Object
Get the number of characters in the string.
-
#msg_count_lines ⇒ Object
Get the number of lines in the string.
-
#msg_count_words ⇒ Object
Get the number of words in the string.
-
#msg_decode64 ⇒ Object
Decode the string from base64.
-
#msg_down ⇒ Object
Convert string to lower case.
-
#msg_encode64 ⇒ Object
Encode the string as base64.
-
#msg_ends_with? ⇒ Boolean
Does the string end with the given string?.
-
#msg_escape ⇒ Object
Escape the string.
-
#msg_format_for_html ⇒ Object
Convert whitespace to HTML friendly spaces.
-
#msg_gen_alphanumeric ⇒ Object
Generate a random alphanumeric string.
-
#msg_gen_base64 ⇒ Object
Generate a random base64 string.
-
#msg_gen_hex ⇒ Object
Generate a random hex string.
-
#msg_gen_uuid ⇒ Object
Generate a new UUID in the string.
-
#msg_gsub ⇒ Object
Substitute the given string with another string.
-
#msg_size ⇒ Object
Get the size of the string.
-
#msg_starts_with? ⇒ Boolean
Does the string start with the given string?.
-
#msg_sub ⇒ Object
Substitute the given string with another string.
-
#msg_substring? ⇒ Boolean
Does the string contain the given string?.
-
#msg_trim ⇒ Object
Strip whitespace from the beginning and end of the string.
-
#msg_unescape ⇒ Object
Unescape the string.
-
#msg_up ⇒ Object
Convert string to upper case.
Instance Method Details
#msg_count_chars ⇒ Object
Get the number of characters in the string.
139 140 141 142 143 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 139 def msg_count_chars s = value.chars.count @engine.heap.it.set_to s return s end |
#msg_count_lines ⇒ Object
Get the number of lines in the string.
157 158 159 160 161 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 157 def msg_count_lines s = value.split( "\n" ).count @engine.heap.it.set_to s return s end |
#msg_count_words ⇒ Object
Get the number of words in the string.
148 149 150 151 152 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 148 def msg_count_words s = value.split( " " ).count @engine.heap.it.set_to s return s end |
#msg_decode64 ⇒ Object
Decode the string from base64. Changes the value of the string.
228 229 230 231 232 233 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 228 def msg_decode64 s = Base64.decode64( value ) set_value s @engine.heap.it.set_to s return s end |
#msg_down ⇒ Object
Convert string to lower case
315 316 317 318 319 320 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 315 def msg_down s = value.downcase set_value s @engine.heap.it.set_to s return s end |
#msg_encode64 ⇒ Object
Encode the string as base64. Changes the value of the string.
217 218 219 220 221 222 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 217 def msg_encode64 s = Base64.encode64( value ) set_value s @engine.heap.it.set_to s return s end |
#msg_ends_with? ⇒ Boolean
Does the string end with the given string?
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 46 def msg_ends_with? if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate result = value.end_with?( data ) @engine.heap.it.set_to result return result else # Error @engine.log.error MISSING_PARAM_MSG @engine.heap.it.set_to false return false end end |
#msg_escape ⇒ Object
Escape the string. Make it URL safe. The value of the string is changed.
195 196 197 198 199 200 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 195 def msg_escape s = URI::DEFAULT_PARSER.escape( value ) set_value s @engine.heap.it.set_to s return s end |
#msg_format_for_html ⇒ Object
Convert whitespace to HTML friendly spaces.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 166 def msg_format_for_html text = self.value out = "" return out unless text # indentation text.each_line do |line| i = 0 while line[i] == ' ' i += 1 out << " " end i = 0 while line[i] == "\t" i += 1 out << " " end out << line end self.value = out.gsub( "\n", "<br/>" ) end |
#msg_gen_alphanumeric ⇒ Object
Generate a random alphanumeric string. By default the length is 10 characters. Set the length with an optional parameter.
250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 250 def msg_gen_alphanumeric len = 10 if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate len = data.to_i end s = StringGenerator.alphanumeric( len ) set_value s @engine.heap.it.set_to s return s end |
#msg_gen_base64 ⇒ Object
Generate a random base64 string. By default the length is 12 characters. Set the length with an optional parameter.
288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 288 def msg_gen_base64 len = 12 if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate len = data.to_i end s = StringGenerator.base64( len ) set_value s @engine.heap.it.set_to s return s end |
#msg_gen_hex ⇒ Object
Generate a random hex string. By default the length is 10 hex characters. Set the length with an optional parameter.
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 269 def msg_gen_hex len = 10 if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate len = data.to_i end s = StringGenerator.hex( len ) set_value s @engine.heap.it.set_to s return s end |
#msg_gen_uuid ⇒ Object
Generate a new UUID in the string.
238 239 240 241 242 243 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 238 def msg_gen_uuid s = StringGenerator.uuid set_value s @engine.heap.it.set_to s return s end |
#msg_gsub ⇒ Object
Substitute the given string with another string. Find all occurrences and replace them.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 88 def msg_gsub if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, [ @params.tokens.first ] ) from = expr.evaluate expr = Gloo::Expr::Expression.new( @engine, [ @params.tokens.last ] ) to = expr.evaluate result = value.gsub(from, to) @engine.heap.it.set_to result set_value(result) return result else # Error @engine.log.error MISSING_PARAM_MSG @engine.heap.it.set_to false return false end end |
#msg_size ⇒ Object
Get the size of the string.
130 131 132 133 134 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 130 def msg_size s = value.size @engine.heap.it.set_to s return s end |
#msg_starts_with? ⇒ Boolean
Does the string start with the given string?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 27 def msg_starts_with? if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate result = self.value.start_with?( data ) @engine.heap.it.set_to result return result else # Error @engine.log.error MISSING_PARAM_MSG @engine.heap.it.set_to false return false end end |
#msg_sub ⇒ Object
Substitute the given string with another string.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 65 def msg_sub if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, [ @params.tokens.first ] ) from = expr.evaluate expr = Gloo::Expr::Expression.new( @engine, [ @params.tokens.last ] ) to = expr.evaluate result = value.sub(from, to) @engine.heap.it.set_to result set_value(result) return result else # Error @engine.log.error MISSING_PARAM_MSG @engine.heap.it.set_to false return false end end |
#msg_substring? ⇒ Boolean
Does the string contain the given string?
This was formerly an overload of obj.contains? Contains? for the Obj checks for the presense of children.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 113 def msg_substring? if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate result = value.include?( data ) @engine.heap.it.set_to result return result else @engine.heap.it.set_to false return false end end |
#msg_trim ⇒ Object
Strip whitespace from the beginning and end of the string.
17 18 19 20 21 22 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 17 def msg_trim result = value.strip @engine.heap.it.set_to result set_value(result) return result end |
#msg_unescape ⇒ Object
Unescape the string. The value of the string is changed.
206 207 208 209 210 211 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 206 def msg_unescape s = URI::DEFAULT_PARSER.unescape( value ) set_value s @engine.heap.it.set_to s return s end |
#msg_up ⇒ Object
Convert string to upper case
305 306 307 308 309 310 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 305 def msg_up s = value.upcase set_value s @engine.heap.it.set_to s return s end |