Class: Prawn::Reference

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Reference

Returns a new instance of Reference.



18
19
20
21
22
23
# File 'lib/prawn/reference.rb', line 18

def initialize(id,data)
  @identifier = id 
  @gen   = 0       
  @data  = data     
  @compressed = false
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



15
16
17
# File 'lib/prawn/reference.rb', line 15

def data
  @data
end

#genObject

Returns the value of attribute gen.



15
16
17
# File 'lib/prawn/reference.rb', line 15

def gen
  @gen
end

#identifierObject (readonly)

Returns the value of attribute identifier.



16
17
18
# File 'lib/prawn/reference.rb', line 16

def identifier
  @identifier
end

#offsetObject

Returns the value of attribute offset.



15
16
17
# File 'lib/prawn/reference.rb', line 15

def offset
  @offset
end

#streamObject (readonly)

Returns the value of attribute stream.



16
17
18
# File 'lib/prawn/reference.rb', line 16

def stream
  @stream
end

Instance Method Details

#<<(data) ⇒ Object



34
35
36
37
# File 'lib/prawn/reference.rb', line 34

def <<(data)
  raise 'Cannot add data to a stream that is compressed' if @compressed
  (@stream ||= "") << data  
end

#compress_streamObject



43
44
45
46
47
# File 'lib/prawn/reference.rb', line 43

def compress_stream
  @stream = Zlib::Deflate.deflate(@stream)
  @data[:Filter] = :FlateDecode
  @compressed = true
end

#objectObject



25
26
27
28
29
30
31
32
# File 'lib/prawn/reference.rb', line 25

def object 
  output = "#{@identifier} #{gen} obj\n" <<
           Prawn::PdfObject(data) << "\n"
  if @stream
    output << "stream\n" << @stream << "\nendstream\n" 
  end
  output << "endobj\n"
end

#to_sObject



39
40
41
# File 'lib/prawn/reference.rb', line 39

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