Class: PDF::Core::Reference

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Reference

Returns a new instance of Reference.



14
15
16
17
18
19
# File 'lib/pdf/core/reference.rb', line 14

def initialize(id, data)
  @identifier = id
  @gen        = 0
  @data       = data
  @stream     = Stream.new
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/pdf/core/reference.rb', line 12

def data
  @data
end

#genObject

Returns the value of attribute gen.



12
13
14
# File 'lib/pdf/core/reference.rb', line 12

def gen
  @gen
end

#identifierObject

Returns the value of attribute identifier.



12
13
14
# File 'lib/pdf/core/reference.rb', line 12

def identifier
  @identifier
end

#offsetObject

Returns the value of attribute offset.



12
13
14
# File 'lib/pdf/core/reference.rb', line 12

def offset
  @offset
end

#streamObject

Returns the value of attribute stream.



12
13
14
# File 'lib/pdf/core/reference.rb', line 12

def stream
  @stream
end

Instance Method Details

#<<(io) ⇒ Object



33
34
35
36
37
38
# File 'lib/pdf/core/reference.rb', line 33

def <<(io)
  unless @data.is_a?(::Hash)
    raise 'Cannot attach stream to non-dictionary object'
  end
  (@stream ||= Stream.new) << io
end

#deep_copy(share = []) ⇒ Object

Creates a deep copy of this ref. If share is provided, shares the given dictionary entries between the old ref and the new.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pdf/core/reference.rb', line 47

def deep_copy(share = [])
  r = dup

  case r.data
  when ::Hash
    # Copy each entry not in +share+.
    (r.data.keys - share).each do |k|
      r.data[k] = Utils.deep_clone(r.data[k])
    end
  when PDF::Core::NameTree::Node
    r.data = r.data.deep_copy
  else
    r.data = Utils.deep_clone(r.data)
  end

  r.stream = Utils.deep_clone(r.stream)
  r
end

#objectObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pdf/core/reference.rb', line 21

def object
  output = "#{@identifier} #{gen} obj\n"
  if @stream.empty?
    output << PDF::Core.pdf_object(data) << "\n"
  else
    output << PDF::Core.pdf_object(data.merge(@stream.data)) <<
      "\n" << @stream.object
  end

  output << "endobj\n"
end

#replace(other_ref) ⇒ Object

Replaces the data and stream with that of other_ref.



67
68
69
70
# File 'lib/pdf/core/reference.rb', line 67

def replace(other_ref)
  @data   = other_ref.data
  @stream = other_ref.stream
end

#to_sObject



40
41
42
# File 'lib/pdf/core/reference.rb', line 40

def to_s
  "#{@identifier} #{gen} R"
end