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
Stream::DEFINED_FILTERS, Stream::TOKENS
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
(also: #each_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(raw_data = ::String.new, dictionary = {}) ⇒ ObjectStream
constructor
Creates a new Object Stream.
-
#length ⇒ Object
Returns the number of objects contained in the stream.
-
#objects ⇒ Object
Returns the array of inner objects.
-
#pre_build ⇒ Object
:nodoc:.
Methods inherited from Stream
#[], #[]=, #cast_to, #data, #data=, #decode!, #each_filter, #each_key, #each_pair, #encode!, #encoded_data, #encoded_data=, #filters, #key?, #keys, parse, #post_build, #set_predictor, #to_obfuscated_str, #to_s, #value
Methods included from TypeGuessing
Methods included from FieldAccessor
#method_missing, #respond_to_missing?
Methods included from StandardObject
Methods included from Object
#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs
Constructor Details
#initialize(raw_data = ::String.new, dictionary = {}) ⇒ ObjectStream
Creates a new Object Stream.
- dictionary
A hash of attributes to set to the Stream.
- raw_data
The Stream data.
488 489 490 491 492 |
# File 'lib/origami/stream.rb', line 488 def initialize(raw_data = ::String.new, dictionary = {}) super @objects = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Origami::FieldAccessor
Instance Method Details
#<<(object) ⇒ Object Also known as: insert
Adds a new Object to this Stream.
- object
The Object to append.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/origami/stream.rb', line 526 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 # We must have an associated document to generate new object numbers. if @document.nil? raise InvalidObjectError, "The ObjectStream must be added to a document before inserting objects" end # The object already belongs to a document. unless object.document.nil? object = import_object_from_document(object) end load! object.no, object.generation = @document.allocate_new_object_number if object.no == 0 store_object(object) Reference.new(object.no, 0) end |
#delete(no) ⇒ Object
Deletes Object no.
557 558 559 560 561 |
# File 'lib/origami/stream.rb', line 557 def delete(no) load! @objects.delete(no) end |
#each(&b) ⇒ Object Also known as: each_object
Iterates over each object in the stream.
606 607 608 609 610 |
# File 'lib/origami/stream.rb', line 606 def each(&b) load! @objects.values.each(&b) end |
#extract(no) ⇒ Object
Returns a given decompressed object contained in the Stream.
- no
The Object number.
574 575 576 577 578 |
# File 'lib/origami/stream.rb', line 574 def extract(no) load! @objects[no] end |
#extract_by_index(index) ⇒ Object
Returns a given decompressed object by index.
- index
The Object index in the ObjectStream.
584 585 586 587 588 589 590 591 |
# File 'lib/origami/stream.rb', line 584 def extract_by_index(index) load! raise TypeError, "index must be an integer" unless index.is_a?(::Integer) raise IndexError, "index #{index} out of range" if index < 0 or index >= @objects.size @objects.to_a.sort[index][1] end |
#include?(no) ⇒ Boolean
Returns whether a specific object is contained in this stream.
- no
The Object number.
597 598 599 600 601 |
# File 'lib/origami/stream.rb', line 597 def include?(no) load! @objects.include?(no) end |
#index(no) ⇒ Object
Returns the index of Object no.
566 567 568 |
# File 'lib/origami/stream.rb', line 566 def index(no) @objects.to_a.sort.index { |num, _| num == no } end |
#length ⇒ Object
Returns the number of objects contained in the stream.
616 617 618 619 620 |
# File 'lib/origami/stream.rb', line 616 def length raise InvalidObjectStreamObjectError, "Invalid number of objects" unless self.N.is_a?(Integer) self.N.to_i end |
#objects ⇒ Object
Returns the array of inner objects.
625 626 627 628 629 |
# File 'lib/origami/stream.rb', line 625 def objects load! @objects.values end |
#pre_build ⇒ Object
:nodoc:
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/origami/stream.rb', line 494 def pre_build #:nodoc: load! prolog = ::String.new data = ::String.new objoff = 0 @objects.to_a.sort.each do |num,obj| obj.set_indirect(false) obj.objstm_offset = objoff prolog << "#{num} #{objoff} " objdata = "#{obj} " 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 |