Class: Gloo::Objs::String

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/basic/string.rb

Constant Summary collapse

KEYWORD =
'string'.freeze
KEYWORD_SHORT =
'str'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #is_alias?, #is_function?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



44
45
46
47
# File 'lib/gloo/objs/basic/string.rb', line 44

def self.messages
  return super + %w[up down size encode64 decode64 escape unescape
    gen_alphanumeric gen_uuid gen_hex gen_base64]
end

.short_typenameObject

The short name of the object type.



26
27
28
# File 'lib/gloo/objs/basic/string.rb', line 26

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



19
20
21
# File 'lib/gloo/objs/basic/string.rb', line 19

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_decode64Object

Decode the string from base64. Changes the value of the string.



96
97
98
99
100
101
# File 'lib/gloo/objs/basic/string.rb', line 96

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



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

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.



85
86
87
88
89
90
# File 'lib/gloo/objs/basic/string.rb', line 85

def msg_encode64
  s = Base64.encode64( value )
  set_value s
  @engine.heap.it.set_to s
  return s
end

#msg_escapeObject

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



63
64
65
66
67
68
# File 'lib/gloo/objs/basic/string.rb', line 63

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

#msg_gen_alphanumericObject

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



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/gloo/objs/basic/string.rb', line 118

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.



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gloo/objs/basic/string.rb', line 156

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.



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/gloo/objs/basic/string.rb', line 137

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.



106
107
108
109
110
111
# File 'lib/gloo/objs/basic/string.rb', line 106

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

#msg_sizeObject

Get the size of the string.



52
53
54
55
56
# File 'lib/gloo/objs/basic/string.rb', line 52

def msg_size
  s = value.size
  @engine.heap.it.set_to s
  return s
end

#msg_unescapeObject

Unescape the string. The value of the string is changed.



74
75
76
77
78
79
# File 'lib/gloo/objs/basic/string.rb', line 74

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



173
174
175
176
177
178
# File 'lib/gloo/objs/basic/string.rb', line 173

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

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



33
34
35
# File 'lib/gloo/objs/basic/string.rb', line 33

def set_value( new_value )
  self.value = new_value.to_s
end