Module: Origami::CompoundObject

Includes:
Object, ObjectCache
Included in:
Array, Dictionary
Defined in:
lib/origami/compound.rb

Overview

Module for objects containing other objects.

Constant Summary

Constants included from Object

Object::TOKENS

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

Methods included from ObjectCache

#initialize, #rebuild_caches

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

#copyObject

Creates a deep copy of the compound object. This method can be quite expensive as nested objects are copied too.



115
116
117
118
119
# File 'lib/origami/compound.rb', line 115

def copy
  obj = update_values(&:copy)

  transfer_attributes(obj)
end

#delete(item) ⇒ Object

Removes the item from the compound object if present.



106
107
108
109
# File 'lib/origami/compound.rb', line 106

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.

Returns:



99
100
101
# File 'lib/origami/compound.rb', line 99

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.

Raises:

  • (NotImplementedError)


124
125
126
127
128
129
130
# File 'lib/origami/compound.rb', line 124

def update_values(&b)
  return enum_for(__method__) unless block_given?
  return self.class.new transform_values(&b) if respond_to?(:transform_values)
  return self.class.new map(&b) if 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.

Raises:

  • (NotImplementedError)


135
136
137
138
139
140
141
# File 'lib/origami/compound.rb', line 135

def update_values!(&b)
  return enum_for(__method__) unless block_given?
  return transform_values!(&b) if respond_to?(:transform_values!)
  return map!(&b) if respond_to?(:map!)

  raise NotImplementedError, "This object does not implement this method"
end