Class: PDF::Core::Reference Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/core/reference.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

PDF indirect objects

Defined Under Namespace

Classes: CannotAttachStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Reference.

Parameters:

  • id (Integer)

    Object identifier

  • data (any)

    Object data

Source Code
lib/pdf/core/reference.rb, line 42
42
def initialize(id, data)
43
  @identifier = id
44
  @gen = 0
45
  @data = data
46
  @stream = Stream.new
47
end

Instance Attribute Details

#dataany

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object data

Returns:

  • (any)
Source Code
lib/pdf/core/reference.rb, line 21
21
def data
22
  @data
23
end

#genInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object generation

Returns:

  • (Integer)
Source Code
lib/pdf/core/reference.rb, line 17
17
def gen
18
  @gen
19
end

#identifierInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object identifier

Returns:

  • (Integer)
Source Code
lib/pdf/core/reference.rb, line 13
13
def identifier
14
  @identifier
15
end

#offsetInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Offset of the serialized object in the document

Returns:

  • (Integer)
Source Code
lib/pdf/core/reference.rb, line 25
25
def offset
26
  @offset
27
end

#streamStream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object stream

Returns:

Source Code
lib/pdf/core/reference.rb, line 29
29
def stream
30
  @stream
31
end

Instance Method Details

#<<(io) ⇒ io

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Appends data to object stream

Parameters:

  • io (String)

    data

Returns:

  • (io)

Raises:

Source Code
lib/pdf/core/reference.rb, line 69
69
def <<(io)
70
  unless @data.is_a?(::Hash)
71
    raise CannotAttachStream
72
  end
73
74
  (@stream ||= Stream.new) << io
75
end

#deep_copy(share = []) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a deep copy of this ref.

Parameters:

  • share (Array<Symbol>) (defaults to: [])

    a list of dictionary entries to share between the old ref and the new

Returns:

Source Code
lib/pdf/core/reference.rb, line 89
89
def deep_copy(share = [])
90
  r = dup
91
92
  case r.data
93
  when ::Hash
94
    # Copy each entry not in +share+.
95
    (r.data.keys - share).each do |k|
96
      r.data[k] = Utils.deep_clone(r.data[k])
97
    end
98
  when PDF::Core::NameTree::Node
99
    r.data = r.data.deep_copy
100
  else
101
    r.data = Utils.deep_clone(r.data)
102
  end
103
104
  r.stream = Utils.deep_clone(r.stream)
105
  r
106
end

#objectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialized PDF object

Returns:

  • (String)
Source Code
lib/pdf/core/reference.rb, line 52
52
def object
53
  output = +"#{@identifier} #{gen} obj\n"
54
  if @stream.empty?
55
    output << PDF::Core.pdf_object(data) << "\n"
56
  else
57
    output << PDF::Core.pdf_object(data.merge(@stream.data)) <<
58
      "\n" << @stream.object
59
  end
60
61
  output << "endobj\n"
62
end

#replace(other_ref) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Replaces the data and stream with that of other_ref.

Parameters:

Source Code
lib/pdf/core/reference.rb, line 112
112
def replace(other_ref)
113
  @data = other_ref.data
114
  @stream = other_ref.stream
115
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object reference in PDF format

Returns:

  • (String)
Source Code
lib/pdf/core/reference.rb, line 80
80
def to_s
81
  "#{@identifier} #{gen} R"
82
end