Module: Gloo::Objs::StringMsgs

Included in:
String, Text
Defined in:
lib/gloo/objs/basic/string_msgs.rb

Instance Method Summary collapse

Instance Method Details

#msg_count_charsObject

Get the number of characters in the string.



128
129
130
131
132
# File 'lib/gloo/objs/basic/string_msgs.rb', line 128

def msg_count_chars
  s = value.chars.count
  @engine.heap.it.set_to s
  return s
end

#msg_count_linesObject

Get the number of lines in the string.



146
147
148
149
150
# File 'lib/gloo/objs/basic/string_msgs.rb', line 146

def msg_count_lines
  s = value.split( "\n" ).count
  @engine.heap.it.set_to s
  return s
end

#msg_count_wordsObject

Get the number of words in the string.



137
138
139
140
141
# File 'lib/gloo/objs/basic/string_msgs.rb', line 137

def msg_count_words
  s = value.split( " " ).count
  @engine.heap.it.set_to s
  return s
end

#msg_decode64Object

Decode the string from 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_decode64
  s = Base64.decode64( value )
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_downObject

Convert string to lower case



304
305
306
307
308
309
# File 'lib/gloo/objs/basic/string_msgs.rb', line 304

def msg_down
  s = value.downcase
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_encode64Object

Encode the string as base64. Changes the value of the string.



206
207
208
209
210
211
# File 'lib/gloo/objs/basic/string_msgs.rb', line 206

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?

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gloo/objs/basic/string_msgs.rb', line 35

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_escapeObject

Escape the string. Make it URL safe. The value of the string is changed.



184
185
186
187
188
189
# File 'lib/gloo/objs/basic/string_msgs.rb', line 184

def msg_escape
  s = URI::DEFAULT_PARSER.escape( value )
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_format_for_htmlObject

Convert whitespace to HTML friendly spaces.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/gloo/objs/basic/string_msgs.rb', line 155

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 << "&nbsp;"
    end
    
    i = 0
    while line[i] == "\t"
      i += 1
      out << "&nbsp;&nbsp;&nbsp;&nbsp;"
    end
    out << line
  end
    
  self.value = out.gsub( "\n", "<br/>" )
end

#msg_gen_alphanumericObject

Generate a random alphanumeric string. By default the length is 10 characters. Set the length with an optional parameter.



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/gloo/objs/basic/string_msgs.rb', line 239

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_base64Object

Generate a random base64 string. By default the length is 12 characters. Set the length with an optional parameter.



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/gloo/objs/basic/string_msgs.rb', line 277

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_hexObject

Generate a random hex string. By default the length is 10 hex characters. Set the length with an optional parameter.



258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/gloo/objs/basic/string_msgs.rb', line 258

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_uuidObject

Generate a new UUID in the string.



227
228
229
230
231
232
# File 'lib/gloo/objs/basic/string_msgs.rb', line 227

def msg_gen_uuid
  s = StringGenerator.uuid
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_gsubObject

Substitute the given string with another string. Find all occurrences and replace them.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/gloo/objs/basic/string_msgs.rb', line 77

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_sizeObject

Get the size of the string.



119
120
121
122
123
# File 'lib/gloo/objs/basic/string_msgs.rb', line 119

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?

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gloo/objs/basic/string_msgs.rb', line 16

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_subObject

Substitute the given string with another string.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gloo/objs/basic/string_msgs.rb', line 54

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.

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gloo/objs/basic/string_msgs.rb', line 102

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_unescapeObject

Unescape the string. 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_unescape
  s = URI::DEFAULT_PARSER.unescape( value )
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_upObject

Convert string to upper case



294
295
296
297
298
299
# File 'lib/gloo/objs/basic/string_msgs.rb', line 294

def msg_up
  s = value.upcase
  set_value s
  @engine.heap.it.set_to s
  return s
end