Class: Origami::Reference
- Inherits:
-
Object
- Object
- Origami::Reference
- Includes:
- Object
- Defined in:
- lib/origami/reference.rb,
lib/origami/obfuscation.rb
Overview
Class representing a Reference Object. Reference are like symbolic links pointing to a particular object into the file.
Constant Summary collapse
- TOKENS =
:nodoc:
[ "(\\d+)" + WHITESPACES + "(\\d+)" + WHITESPACES + "R" ]
- REGEXP_TOKEN =
Regexp.new(TOKENS.first, Regexp::MULTILINE)
- @@regexp =
Regexp.new(WHITESPACES + TOKENS.first + WHITESPACES)
Instance Attribute Summary collapse
-
#refgen ⇒ Object
Returns the value of attribute refgen.
-
#refno ⇒ Object
Returns the value of attribute refno.
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Class Method Summary collapse
-
.parse(stream) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#<=>(ref) ⇒ Object
:nodoc.
-
#eql?(ref) ⇒ Boolean
:nodoc.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(refno, refgen) ⇒ Reference
constructor
A new instance of Reference.
- #real_type ⇒ Object
- #solve ⇒ Object
-
#to_a ⇒ Object
Returns a Ruby array with the object number and the generation this reference is pointing to.
- #to_obfuscated_str ⇒ Object
-
#to_s ⇒ Object
:nodoc:.
-
#value ⇒ Object
Returns self.
Methods included from Object
#copy, #indirect_parent, #is_indirect?, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #to_o, #type, typeof, #xrefs
Constructor Details
#initialize(refno, refgen) ⇒ Reference
Returns a new instance of Reference.
41 42 43 |
# File 'lib/origami/reference.rb', line 41 def initialize(refno, refgen) @refno, @refgen = refno, refgen end |
Instance Attribute Details
#refgen ⇒ Object
Returns the value of attribute refgen.
39 40 41 |
# File 'lib/origami/reference.rb', line 39 def refgen @refgen end |
#refno ⇒ Object
Returns the value of attribute refno.
39 40 41 |
# File 'lib/origami/reference.rb', line 39 def refno @refno end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/origami/reference.rb', line 45 def self.parse(stream) #:nodoc: offset = stream.pos if stream.scan(@@regexp).nil? raise InvalidReferenceError, "Bad reference to indirect objet format" end refno = stream[2].to_i refgen = stream[4].to_i ref = Reference.new(refno,refgen) ref.file_offset = offset ref end |
Instance Method Details
#<=>(ref) ⇒ Object
:nodoc
87 88 89 |
# File 'lib/origami/reference.rb', line 87 def <=>(ref) #:nodoc self.to_a <=> ref.to_a end |
#eql?(ref) ⇒ Boolean
:nodoc
79 80 81 |
# File 'lib/origami/reference.rb', line 79 def eql?(ref) #:nodoc ref.is_a?(Reference) and ref.refno == @refno and ref.refgen == @refgen end |
#hash ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/origami/reference.rb', line 83 def hash #:nodoc: self.to_a.hash end |
#solve ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/origami/reference.rb', line 62 def solve pdfdoc = self.pdf if pdfdoc.nil? raise InvalidReferenceError, "Not attached to any PDF" end target = pdfdoc.get_object(self) if target.nil? raise InvalidReferenceError, "Cannot resolve reference : #{self.to_s}" end target end |
#to_a ⇒ Object
Returns a Ruby array with the object number and the generation this reference is pointing to.
94 95 96 |
# File 'lib/origami/reference.rb', line 94 def to_a [@refno, @refgen] end |
#to_obfuscated_str ⇒ Object
165 166 167 168 169 |
# File 'lib/origami/obfuscation.rb', line 165 def refstr = refno.to_s + Obfuscator.junk_spaces + refgen.to_s + Obfuscator.junk_spaces + "R" super(refstr) end |
#to_s ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/origami/reference.rb', line 98 def to_s #:nodoc: super("#{@refno} #{@refgen} R") end |
#value ⇒ Object
Returns self.
105 106 107 |
# File 'lib/origami/reference.rb', line 105 def value self end |