Class: String

Inherits:
Object show all
Defined in:
lib/dns_one/core_ext/blank.rb,
lib/dns_one/core_ext/string.rb

Constant Summary collapse

LOCAL_BLANK_RE =
/\A[[:space:]]*\z/

Instance Method Summary collapse

Instance Method Details

#blank?true, false

A string is blank if it’s empty or contains whitespaces only:

''.blank?       # => true
'   '.blank?    # => true
"\t\n\r".blank? # => true
' blah '.blank? # => false

Unicode whitespace is supported:

"\u00a0".blank? # => true

Returns:

  • (true, false)


129
130
131
132
133
134
# File 'lib/dns_one/core_ext/blank.rb', line 129

def blank?
  # The regexp that matches blank strings is expensive. For the case of empty
  # strings we can speed up this method (~3.5x) with an empty? call. The
  # penalty for the rest of strings is marginal.
  empty? || LOCAL_BLANK_RE.match?(self)
end

#strip_textObject



6
7
8
9
10
# File 'lib/dns_one/core_ext/string.rb', line 6

def strip_text
    split("\n")
    .map{|l| l.strip}
    .join("\n")
end

#to_aObject



3
4
5
# File 'lib/dns_one/core_ext/string.rb', line 3

def to_a
    [self]
end