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.
144 145 146 147 148 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 144 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.
162 163 164 165 166 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 162 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.
153 154 155 156 157 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 153 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.
233 234 235 236 237 238 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 233 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
320 321 322 323 324 325 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 320 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.
222 223 224 225 226 227 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 222 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?
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 48 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.
200 201 202 203 204 205 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 200 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.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 171 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.
255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 255 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.
293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 293 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.
274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 274 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.
243 244 245 246 247 248 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 243 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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 91 def msg_gsub return '' unless value 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.
135 136 137 138 139 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 135 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?
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 29 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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 67 def msg_sub return '' unless value 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.
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 118 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 23 24 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 17 def msg_trim return '' unless value 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.
211 212 213 214 215 216 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 211 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
310 311 312 313 314 315 |
# File 'lib/gloo/objs/basic/string_msgs.rb', line 310 def msg_up s = value.upcase set_value s @engine.heap.it.set_to s return s end |