Class: QuickAndRuby::DistinguishedName

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

Defined Under Namespace

Classes: Attribute

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = []) ⇒ DistinguishedName

Returns a new instance of DistinguishedName.



7
8
9
# File 'lib/quick_and_ruby/distinguished_name.rb', line 7

def initialize(attributes = [])
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/quick_and_ruby/distinguished_name.rb', line 5

def attributes
  @attributes
end

Class Method Details

.from_string(dn_str) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/quick_and_ruby/distinguished_name.rb', line 24

def self.from_string(dn_str)
  attributes = dn_str.split(/(?<!\\),/).map do |dn_component|
    unless (match = /^([^=]+)=(.*)$/.match(dn_component.strip))
      raise "#{dn_component} is not a valid DistinguishedName component"
    end

    Attribute.new(*match.captures)
  end

  new(attributes)
end

Instance Method Details

#reverseObject



20
21
22
# File 'lib/quick_and_ruby/distinguished_name.rb', line 20

def reverse
  self.class.new(attributes.reverse)
end

#sizeObject Also known as: length



15
16
17
# File 'lib/quick_and_ruby/distinguished_name.rb', line 15

def size
  @attributes.size
end

#to_sObject



11
12
13
# File 'lib/quick_and_ruby/distinguished_name.rb', line 11

def to_s
  attributes.map(&:to_s).join(',')
end