Class: LX::String

Inherits:
Object
  • Object
show all
Defined in:
lib/lx.rb

Overview

Utilities for strings.

Defined Under Namespace

Modules: Dangerous

Instance Method Summary collapse

Constructor Details

#initialize(p_str) ⇒ String

Initializes a LX::String object, The single param is the string with which the object will be associated.



312
313
314
# File 'lib/lx.rb', line 312

def initialize(p_str)
	@str = p_str
end

Instance Method Details

#collapseObject

Returns a new string in which leading and trailing whitespace have been removed, and multiple internal whitespaces are collapsed into into single spaces.

str = ' Whatever  Dude  '
str.lx.collapse # => "Whatever Dude"


329
330
331
332
333
# File 'lib/lx.rb', line 329

def collapse()
	rv = @str.dup
	rv.lx.collapse!
	return rv
end

#collapse!Object

Performs a collapse on the string itself.



336
337
338
339
340
# File 'lib/lx.rb', line 336

def collapse!()
	@str.sub!(/\A[^[:graph:]]+/mu, '')
	@str.sub!(/[^[:graph:]]+\z/mu, '')
	@str.gsub!(/[^[:graph:]]+/mu, ' ')
end

#has_content?Boolean

Same as hascontent?

Returns:

  • (Boolean)


369
370
371
# File 'lib/lx.rb', line 369

def has_content?
	return hascontent?
end

#hascontent?Boolean

Returns true if the string contains a non-whitespace character.

Returns:

  • (Boolean)


364
365
366
# File 'lib/lx.rb', line 364

def hascontent?
	return @str.match(/\S/mu) ? true : false
end

#inner_collapseObject


inner_collapse



349
350
351
352
353
# File 'lib/lx.rb', line 349

def inner_collapse
	rv = @str.clone
	rv.gsub!(/[\u00A0\s]+/imu, ' ')
	return rv
end

#no_content?Boolean

Same as no_content?

Returns:

  • (Boolean)


379
380
381
# File 'lib/lx.rb', line 379

def no_content?
	return nocontent?
end

#nocontent?Boolean

Return true if the string does not have any non-whitespace characters.

Returns:

  • (Boolean)


374
375
376
# File 'lib/lx.rb', line 374

def nocontent?
	return !hascontent?
end

#tmp_untaint(rx) {|tmp| ... } ⇒ Object


tmp_untaint

Yields:

  • (tmp)


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/lx.rb', line 391

def tmp_untaint(rx)
	# dangerous
	if rx == LX::String::Dangerous
		tmp = @str.dup.untaint
	else
		if @str.match(rx)
			tmp = @str.dup.untaint
		else
			raise 'string-does-not-match-untaint-pattern: ' + rx.to_s
		end
	end
	
	# yield
	yield tmp
end