Class: Origami::Reference
- Inherits:
-
Object
- Object
- Origami::Reference
- Includes:
- Comparable, 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:
[ "(?<no>\\d+)" + WHITESPACES + "(?<gen>\\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.
-
#==(ref) ⇒ Object
(also: #eql?)
Compares to Reference object.
-
#follow ⇒ Object
(also: #solve)
Returns the object pointed to by the reference.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(refno, refgen) ⇒ Reference
constructor
A new instance of Reference.
-
#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(eol: $/) ⇒ Object
:nodoc:.
-
#valid? ⇒ Boolean
Returns true if the reference points to an object.
-
#value ⇒ Object
Returns the referenced object value.
Methods included from Object
#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #to_o, #type, typeof, #version_required, #xrefs
Constructor Details
#initialize(refno, refgen) ⇒ Reference
Returns a new instance of Reference.
40 41 42 43 44 |
# File 'lib/origami/reference.rb', line 40 def initialize(refno, refgen) super() @refno, @refgen = refno, refgen end |
Instance Attribute Details
#refgen ⇒ Object
Returns the value of attribute refgen.
38 39 40 |
# File 'lib/origami/reference.rb', line 38 def refgen @refgen end |
#refno ⇒ Object
Returns the value of attribute refno.
38 39 40 |
# File 'lib/origami/reference.rb', line 38 def refno @refno end |
Class Method Details
.parse(stream, _parser = nil) ⇒ Object
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/origami/reference.rb', line 46 def self.parse(stream, _parser = nil) #:nodoc: scanner = Parser.init_scanner(stream) offset = scanner.pos if scanner.scan(@@regexp).nil? raise InvalidReferenceError, "Bad reference to indirect objet format" end no = scanner['no'].to_i gen = scanner['gen'].to_i ref = Reference.new(no, gen) ref.file_offset = offset ref end |
Instance Method Details
#<=>(ref) ⇒ Object
:nodoc
101 102 103 |
# File 'lib/origami/reference.rb', line 101 def <=>(ref) #:nodoc self.to_a <=> ref.to_a end |
#==(ref) ⇒ Object Also known as: eql?
Compares to Reference object.
108 109 110 111 112 |
# File 'lib/origami/reference.rb', line 108 def ==(ref) return false unless ref.is_a?(Reference) self.to_a == ref.to_a end |
#follow ⇒ Object Also known as: solve
Returns the object pointed to by the reference. The reference must be part of a document. Raises an InvalidReferenceError if the object cannot be found.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/origami/reference.rb', line 68 def follow doc = self.document if doc.nil? raise InvalidReferenceError, "Not attached to any document" end target = doc.get_object(self) if target.nil? and not Origami::OPTIONS[:ignore_bad_references] raise InvalidReferenceError, "Cannot resolve reference : #{self}" end target or Null.new end |
#hash ⇒ Object
:nodoc:
97 98 99 |
# File 'lib/origami/reference.rb', line 97 def hash #:nodoc: self.to_a.hash end |
#to_a ⇒ Object
Returns a Ruby array with the object number and the generation this reference is pointing to.
118 119 120 |
# File 'lib/origami/reference.rb', line 118 def to_a [@refno, @refgen] end |
#to_obfuscated_str ⇒ Object
183 184 185 186 187 |
# File 'lib/origami/obfuscation.rb', line 183 def refstr = refno.to_s + Obfuscator.junk_spaces + refgen.to_s + Obfuscator.junk_spaces + "R" super(refstr) end |
#to_s(eol: $/) ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/origami/reference.rb', line 122 def to_s(eol: $/) #:nodoc: super("#{@refno} #{@refgen} R", eol: eol) end |
#valid? ⇒ Boolean
Returns true if the reference points to an object.
88 89 90 91 92 93 94 95 |
# File 'lib/origami/reference.rb', line 88 def valid? begin self.solve true rescue InvalidReferenceError false end end |
#value ⇒ Object
Returns the referenced object value.
129 130 131 |
# File 'lib/origami/reference.rb', line 129 def value self.solve.value end |