Class: Dominus::Document

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/dominus/document.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Document

Returns a new instance of Document.



10
11
12
13
# File 'lib/dominus/document.rb', line 10

def initialize(doc)
  super(doc)
  ObjectSpace.define_finalizer(self, self.class.cleanup(doc))
end

Class Method Details

.cleanup(doc) ⇒ Object



6
7
8
# File 'lib/dominus/document.rb', line 6

def self.cleanup(doc)
  proc { doc.recycle }
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/dominus/document.rb', line 15

def [](key)
  values = get_item_value(key)
  if(values.length < 2)
    values.first
  else
    values.to_a
  end
end

#itemsObject



24
25
26
27
28
29
# File 'lib/dominus/document.rb', line 24

def items
  @items ||= super.each_with_object({}) do |item, hash|
    hash[item.name] = item.values.to_a
    item.recycle
  end
end