Sha256: e4483b52b55c70758908d00d3ced79522b8cd5813d4a9e4b5fc0a3657a0fe1db

Contents?: true

Size: 649 Bytes

Versions: 4

Compression:

Stored size: 649 Bytes

Contents

require 'dnc/dn'

#
# Extend the core String class to include `.to_dn` && `.to_dn!`
#
class String
  # Parses the string to return a DN object
  # Returns nil if a DN instance cannot be created
  def to_dn
    begin
      new_dn = DN.new(dn_string: to_s)
    rescue StandardError
      new_dn = nil
    end

    new_dn
  end

  # Similar to {#to_dn}, but raises an error unless the string can be
  # explicitly parsed to a DN instance
  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dnc-0.1.9 lib/dnc/string.rb
dnc-1.0.0 lib/dnc/string.rb
dnc-0.1.8 lib/dnc/string.rb
dnc-0.1.6 lib/dnc/string.rb