class String

Extend the core String class to include `.to_dn` && `.to_dn!`

Constants

BLANK_RE

Public Instance Methods

blank?() click to toggle source

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

@return [true, false]

# File lib/blank.rb, line 116
def blank?
  BLANK_RE === self
end
to_dn() click to toggle source

Parses the string to return a DN object Returns nil if a DN instance cannot be created

# File lib/dnc/string.rb, line 9
def to_dn
  begin
    new_dn = DN.new(dn_string: to_s)
  rescue StandardError
    new_dn = nil
  end

  new_dn
end
to_dn!() click to toggle source

Similar to {#to_dn}, but raises an error unless the string can be explicitly parsed to a DN instance

# File lib/dnc/string.rb, line 21
def to_dn!
  begin
    new_dn = DN.new(dn_string: to_s)
  rescue StandardError
    raise DnStringUnparsableError,
          "Could not force conversion to DN:\n#{inspect}"
  end

  new_dn
end