Class: Prawn::ObjectStore
- Inherits:
-
Object
- Object
- Prawn::ObjectStore
- Includes:
- Enumerable
- Defined in:
- lib/prawn/object_store.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #each ⇒ Object
-
#initialize(info = {}) ⇒ ObjectStore
constructor
A new instance of ObjectStore.
-
#push(*args, &block) ⇒ Object
(also: #<<)
Adds the given reference to the store and returns the reference object.
- #ref(data, &block) ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
#initialize(info = {}) ⇒ ObjectStore
Returns a new instance of ObjectStore.
12 13 14 15 16 17 18 19 20 |
# File 'lib/prawn/object_store.rb', line 12 def initialize(info={}) @objects = {} @identifiers = [] # Create required PDF roots @info = ref(info).identifier @pages = ref(:Type => :Pages, :Count => 0, :Kids => []).identifier @root = ref(:Type => :Catalog, :Pages => pages).identifier end |
Instance Method Details
#[](id) ⇒ Object
53 54 55 |
# File 'lib/prawn/object_store.rb', line 53 def [](id) @objects[id] end |
#each ⇒ Object
47 48 49 50 51 |
# File 'lib/prawn/object_store.rb', line 47 def each @identifiers.each do |id| yield @objects[id] end end |
#push(*args, &block) ⇒ Object Also known as: <<
Adds the given reference to the store and returns the reference object. If the object provided is not a Prawn::Reference, one is created from the arguments provided.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/prawn/object_store.rb', line 35 def push(*args, &block) reference = if args.first.is_a?(Prawn::Reference) args.first else Prawn::Reference.new(*args, &block) end @objects[reference.identifier] = reference @identifiers << reference.identifier reference end |
#ref(data, &block) ⇒ Object
22 23 24 |
# File 'lib/prawn/object_store.rb', line 22 def ref(data, &block) push(size + 1, data, &block) end |
#size ⇒ Object Also known as: length
57 58 59 |
# File 'lib/prawn/object_store.rb', line 57 def size @identifiers.size end |