Module: Origami::CompoundObject
Overview
Module for objects containing other objects.
Constant Summary
Constants included from Object
Instance Attribute Summary
Attributes included from ObjectCache
#names_cache, #strings_cache, #xref_cache
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Instance Method Summary collapse
-
#copy ⇒ Object
Creates a deep copy of the compound object.
-
#delete(item) ⇒ Object
Removes the item from the compound object if present.
-
#include?(item) ⇒ Boolean
Returns true if the item is present in the compound object.
-
#update_values(&b) ⇒ Object
Returns a new compound object with updated values based on the provided block.
-
#update_values!(&b) ⇒ Object
Modifies the compound object’s values based on the provided block.
Methods included from ObjectCache
Methods included from Object
#cast_to, #document, #export, included, #indirect?, #indirect_parent, #initialize, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs
Instance Method Details
#copy ⇒ Object
Creates a deep copy of the compound object. This method can be quite expensive as nested objects are copied too.
118 119 120 121 122 |
# File 'lib/origami/compound.rb', line 118 def copy obj = self.update_values(&:copy) transfer_attributes(obj) end |
#delete(item) ⇒ Object
Removes the item from the compound object if present.
109 110 111 112 |
# File 'lib/origami/compound.rb', line 109 def delete(item) obj = super(item.to_o) unlink_object(obj) unless obj.nil? end |
#include?(item) ⇒ Boolean
Returns true if the item is present in the compound object.
102 103 104 |
# File 'lib/origami/compound.rb', line 102 def include?(item) super(item.to_o) end |
#update_values(&b) ⇒ Object
Returns a new compound object with updated values based on the provided block.
127 128 129 130 131 132 133 |
# File 'lib/origami/compound.rb', line 127 def update_values(&b) return enum_for(__method__) unless block_given? return self.class.new self.transform_values(&b) if self.respond_to?(:transform_values) return self.class.new self.map(&b) if self.respond_to?(:map) raise NotImplementedError, "This object does not implement this method" end |
#update_values!(&b) ⇒ Object
Modifies the compound object’s values based on the provided block.
138 139 140 141 142 143 144 |
# File 'lib/origami/compound.rb', line 138 def update_values!(&b) return enum_for(__method__) unless block_given? return self.transform_values!(&b) if self.respond_to?(:transform_values!) return self.map!(&b) if self.respond_to?(:map!) raise NotImplementedError, "This object does not implement this method" end |