Class: String

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

Overview

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

Constant Summary collapse

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)


116
117
118
# File 'lib/blank.rb', line 116

def blank?
  BLANK_RE === self
end

#to_dnObject

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



9
10
11
12
13
14
15
16
17
# 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!Object

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



21
22
23
24
25
26
27
28
29
30
# 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