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
Instance Method Summary collapse
-
#<=>(ref) ⇒ Object
:nodoc.
-
#eql?(ref) ⇒ Boolean
:nodoc.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(refno, refgen) ⇒ Reference
constructor
A new instance of Reference.
- #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
#cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, #native_type, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #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.
45 46 47 |
# File 'lib/origami/reference.rb', line 45 def initialize(refno, refgen) @refno, @refgen = refno, refgen end |
Instance Attribute Details
#refgen ⇒ Object
Returns the value of attribute refgen.
43 44 45 |
# File 'lib/origami/reference.rb', line 43 def refgen @refgen end |
#refno ⇒ Object
Returns the value of attribute refno.
43 44 45 |
# File 'lib/origami/reference.rb', line 43 def refno @refno end |
Class Method Details
.native_type ⇒ Object
112 |
# File 'lib/origami/reference.rb', line 112 def self.native_type ; Reference end |
.parse(stream, parser = nil) ⇒ Object
:nodoc:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/origami/reference.rb', line 49 def self.parse(stream, parser = nil) #: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
90 91 92 |
# File 'lib/origami/reference.rb', line 90 def <=>(ref) #:nodoc self.to_a <=> ref.to_a end |
#eql?(ref) ⇒ Boolean
:nodoc
82 83 84 |
# File 'lib/origami/reference.rb', line 82 def eql?(ref) #:nodoc ref.is_a?(Reference) and ref.refno == @refno and ref.refgen == @refgen end |
#hash ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/origami/reference.rb', line 86 def hash #:nodoc: self.to_a.hash end |
#solve ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/origami/reference.rb', line 66 def solve pdfdoc = self.pdf if pdfdoc.nil? raise InvalidReferenceError, "Not attached to any PDF" end target = pdfdoc.get_object(self) if target.nil? and not Origami::OPTIONS[:ignore_bad_references] raise InvalidReferenceError, "Cannot resolve reference : #{self.to_s}" end target or Null.new end |
#to_a ⇒ Object
Returns a Ruby array with the object number and the generation this reference is pointing to.
97 98 99 |
# File 'lib/origami/reference.rb', line 97 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:
101 102 103 |
# File 'lib/origami/reference.rb', line 101 def to_s #:nodoc: super("#{@refno} #{@refgen} R") end |
#value ⇒ Object
Returns self.
108 109 110 |
# File 'lib/origami/reference.rb', line 108 def value self end |