Class: Origami::ObjectStream
- Includes:
- Enumerable
- Defined in:
- lib/origami/stream.rb
Overview
Class representing a Stream containing other Objects.
Constant Summary collapse
- NUM =
:nodoc:
0
- OBJ =
:nodoc:
1
Constants inherited from Stream
Constants included from StandardObject
StandardObject::DEFAULT_ATTRIBUTES
Constants included from Object
Instance Attribute Summary
Attributes inherited from Stream
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Instance Method Summary collapse
-
#<<(object) ⇒ Object
(also: #insert)
Adds a new Object to this Stream.
-
#delete(no) ⇒ Object
Deletes Object no.
-
#each(&b) ⇒ Object
Iterates over each object in the stream.
-
#extract(no) ⇒ Object
Returns a given decompressed object contained in the Stream.
-
#extract_by_index(index) ⇒ Object
Returns a given decompressed object by index.
-
#include?(no) ⇒ Boolean
Returns whether a specific object is contained in this stream.
-
#index(no) ⇒ Object
Returns the index of Object no.
-
#initialize(rawdata = "", dictionary = {}) ⇒ ObjectStream
constructor
Creates a new Object Stream.
-
#objects ⇒ Object
Returns the array of inner objects.
-
#pre_build ⇒ Object
:nodoc:.
Methods inherited from Stream
#[], #[]=, add_type_info, #cast_to, #data, #data=, #decode!, #each_key, #encode!, guess_type, #method_missing, native_type, parse, #post_build, #rawdata, #rawdata=, #set_predictor, #to_obfuscated_str, #to_s, #value
Methods included from StandardObject
#do_type_check, #has_field?, included, #pdf_version_required, #set_default_value, #set_default_values
Methods included from Object
#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, parse, #pdf, #pdf_version_required, #post_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs
Constructor Details
#initialize(rawdata = "", dictionary = {}) ⇒ ObjectStream
Creates a new Object Stream.
- dictionary
-
A hash of attributes to set to the Stream.
- rawdata
-
The Stream data.
456 457 458 459 460 |
# File 'lib/origami/stream.rb', line 456 def initialize(rawdata = "", dictionary = {}) @objects = nil super(rawdata, dictionary) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Origami::Stream
Instance Method Details
#<<(object) ⇒ Object Also known as: insert
Adds a new Object to this Stream.
- object
-
The Object to append.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/origami/stream.rb', line 494 def <<(object) unless object.generation == 0 raise InvalidObjectError, "Cannot store an object with generation > 0 in an ObjectStream" end if object.is_a?(Stream) raise InvalidObjectError, "Cannot store a Stream in an ObjectStream" end load! if @objects.nil? object.no, object.generation = @pdf.alloc_new_object_number if object.no == 0 object.set_indirect(true) # object is indirect object.parent = self # set this stream as the parent object.set_pdf(@pdf) # indirect objects need pdf information @objects[object.no] = object Reference.new(object.no, 0) end |
#delete(no) ⇒ Object
Deletes Object no.
519 520 521 522 523 |
# File 'lib/origami/stream.rb', line 519 def delete(no) load! if @objects.nil? @objects.delete(no) end |
#each(&b) ⇒ Object
Iterates over each object in the stream.
572 573 574 575 576 |
# File 'lib/origami/stream.rb', line 572 def each(&b) load! if @objects.nil? @objects.values.each(&b) end |
#extract(no) ⇒ Object
Returns a given decompressed object contained in the Stream.
- no
-
The Object number.
543 544 545 546 547 |
# File 'lib/origami/stream.rb', line 543 def extract(no) load! if @objects.nil? @objects[no] end |
#extract_by_index(index) ⇒ Object
Returns a given decompressed object by index.
- index
-
The Object index in the ObjectStream.
553 554 555 556 557 |
# File 'lib/origami/stream.rb', line 553 def extract_by_index(index) load! if @objects.nil? @objects.to_a.sort[index] end |
#include?(no) ⇒ Boolean
Returns whether a specific object is contained in this stream.
- no
-
The Object number.
563 564 565 566 567 |
# File 'lib/origami/stream.rb', line 563 def include?(no) load! if @objects.nil? @objects.include?(no) end |
#index(no) ⇒ Object
Returns the index of Object no.
528 529 530 531 532 533 534 535 536 537 |
# File 'lib/origami/stream.rb', line 528 def index(no) ind = 0 @objects.to_a.sort.each { |num, obj| return ind if num == no ind = ind + 1 } nil end |
#objects ⇒ Object
Returns the array of inner objects.
581 582 583 584 585 |
# File 'lib/origami/stream.rb', line 581 def objects load! if @objects.nil? @objects.values end |
#pre_build ⇒ Object
:nodoc:
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/origami/stream.rb', line 462 def pre_build #:nodoc: load! if @objects.nil? prolog = "" data = "" objoff = 0 @objects.to_a.sort.each do |num,obj| obj.set_indirect(false) obj.objstm_offset = objoff prolog << "#{num} #{objoff} " objdata = "#{obj.to_s} " objoff += objdata.size data << objdata obj.set_indirect(true) obj.no = num end self.data = prolog + data @dictionary[:N] = @objects.size @dictionary[:First] = prolog.size super end |