Class: Gloo::Objs::String
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::String
- Defined in:
- lib/gloo/objs/basic/string.rb
Constant Summary collapse
- KEYWORD =
'string'.freeze
- KEYWORD_SHORT =
'str'.freeze
- MISSING_PARAM_MSG =
'Missing parameter!'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#msg_contains? ⇒ Boolean
Does the string contain the given 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_size ⇒ Object
Get the size of the string.
-
#msg_starts_with? ⇒ Boolean
Does the string start with the given string?.
-
#msg_unescape ⇒ Object
Unescape the string.
-
#msg_up ⇒ Object
Convert string to upper case.
-
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
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, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
45 46 47 48 49 |
# File 'lib/gloo/objs/basic/string.rb', line 45 def self. return super + %w[up down size starts_with? ends_with? contains? format_for_html encode64 decode64 escape unescape gen_alphanumeric gen_uuid gen_hex gen_base64] end |
.short_typename ⇒ Object
The short name of the object type.
27 28 29 |
# File 'lib/gloo/objs/basic/string.rb', line 27 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
20 21 22 |
# File 'lib/gloo/objs/basic/string.rb', line 20 def self.typename return KEYWORD end |
Instance Method Details
#msg_contains? ⇒ Boolean
Does the string contain the given string?
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/gloo/objs/basic/string.rb', line 119 def msg_contains? 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 # Error @engine.log.error MISSING_PARAM_MSG @engine.heap.it.set_to false return false end end |
#msg_decode64 ⇒ Object
Decode the string from base64. Changes the value of the string.
182 183 184 185 186 187 |
# File 'lib/gloo/objs/basic/string.rb', line 182 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
269 270 271 272 273 274 |
# File 'lib/gloo/objs/basic/string.rb', line 269 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.
171 172 173 174 175 176 |
# File 'lib/gloo/objs/basic/string.rb', line 171 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?
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gloo/objs/basic/string.rb', line 100 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.
149 150 151 152 153 154 |
# File 'lib/gloo/objs/basic/string.rb', line 149 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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gloo/objs/basic/string.rb', line 54 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.
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/gloo/objs/basic/string.rb', line 204 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.
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/gloo/objs/basic/string.rb', line 242 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.
223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/gloo/objs/basic/string.rb', line 223 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.
192 193 194 195 196 197 |
# File 'lib/gloo/objs/basic/string.rb', line 192 def msg_gen_uuid s = StringGenerator.uuid set_value s @engine.heap.it.set_to s return s end |
#msg_size ⇒ Object
Get the size of the string.
138 139 140 141 142 |
# File 'lib/gloo/objs/basic/string.rb', line 138 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?
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gloo/objs/basic/string.rb', line 81 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_unescape ⇒ Object
Unescape the string. The value of the string is changed.
160 161 162 163 164 165 |
# File 'lib/gloo/objs/basic/string.rb', line 160 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
259 260 261 262 263 264 |
# File 'lib/gloo/objs/basic/string.rb', line 259 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.
34 35 36 |
# File 'lib/gloo/objs/basic/string.rb', line 34 def set_value( new_value ) self.value = new_value.to_s end |