Class: Prawn::Reference
- Inherits:
-
Object
- Object
- Prawn::Reference
- Defined in:
- lib/prawn/reference.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#gen ⇒ Object
Returns the value of attribute gen.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #compress_stream ⇒ Object
-
#initialize(id, data, &block) ⇒ Reference
constructor
A new instance of Reference.
- #object ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, data, &block) ⇒ Reference
Returns a new instance of Reference.
18 19 20 21 22 23 24 |
# File 'lib/prawn/reference.rb', line 18 def initialize(id, data, &block) @identifier = id @gen = 0 @data = data @compressed = false @on_encode = block end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def data @data end |
#gen ⇒ Object
Returns the value of attribute gen.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def gen @gen end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
16 17 18 |
# File 'lib/prawn/reference.rb', line 16 def identifier @identifier end |
#offset ⇒ Object
Returns the value of attribute offset.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def offset @offset end |
#stream ⇒ Object (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
36 37 38 39 |
# File 'lib/prawn/reference.rb', line 36 def <<(data) raise 'Cannot add data to a stream that is compressed' if @compressed (@stream ||= "") << data end |
#compress_stream ⇒ Object
45 46 47 48 49 50 |
# File 'lib/prawn/reference.rb', line 45 def compress_stream @stream = Zlib::Deflate.deflate(@stream) @data[:Filter] = :FlateDecode @data[:Length] ||= @stream.length @compressed = true end |
#object ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/prawn/reference.rb', line 26 def object @on_encode.call(self) if @on_encode output = "#{@identifier} #{gen} obj\n" << Prawn::PdfObject(data) << "\n" if @stream output << "stream\n" << @stream << "\nendstream\n" end output << "endobj\n" end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/prawn/reference.rb', line 41 def to_s "#{@identifier} #{gen} R" end |