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
-
#<=>(other) ⇒ Object
:nodoc.
-
#==(other) ⇒ 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.
39 40 41 42 43 |
# File 'lib/origami/reference.rb', line 39 def initialize(refno, refgen) super() @refno, @refgen = refno, refgen end |
Instance Attribute Details
#refgen ⇒ Object
Returns the value of attribute refgen.
37 38 39 |
# File 'lib/origami/reference.rb', line 37 def refgen @refgen end |
#refno ⇒ Object
Returns the value of attribute refno.
37 38 39 |
# File 'lib/origami/reference.rb', line 37 def refno @refno end |
Class Method Details
.parse(stream, _parser = nil) ⇒ 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, _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
#<=>(other) ⇒ Object
:nodoc
98 99 100 |
# File 'lib/origami/reference.rb', line 98 def <=>(other) # :nodoc to_a <=> other.to_a end |
#==(other) ⇒ Object Also known as: eql?
Compares to Reference object.
105 106 107 108 109 |
# File 'lib/origami/reference.rb', line 105 def ==(other) return false unless other.is_a?(Reference) to_a == other.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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/origami/reference.rb', line 67 def follow doc = document if doc.nil? raise InvalidReferenceError, "Not attached to any document" end target = doc.get_object(self) if target.nil? && !Origami::OPTIONS[:ignore_bad_references] raise InvalidReferenceError, "Cannot resolve reference : #{self}" end target or Null.new end |
#hash ⇒ Object
:nodoc:
94 95 96 |
# File 'lib/origami/reference.rb', line 94 def hash # :nodoc: to_a.hash end |
#to_a ⇒ Object
Returns a Ruby array with the object number and the generation this reference is pointing to.
115 116 117 |
# File 'lib/origami/reference.rb', line 115 def to_a [@refno, @refgen] end |
#to_obfuscated_str ⇒ Object
182 183 184 185 186 |
# File 'lib/origami/obfuscation.rb', line 182 def refstr = refno.to_s + Obfuscator.junk_spaces + refgen.to_s + Obfuscator.junk_spaces + "R" super(refstr) end |
#to_s(eol: $/) ⇒ Object
:nodoc:
119 120 121 |
# File 'lib/origami/reference.rb', line 119 def to_s(eol: $/) # :nodoc: super("#{@refno} #{@refgen} R", eol: eol) end |
#valid? ⇒ Boolean
Returns true if the reference points to an object.
87 88 89 90 91 92 |
# File 'lib/origami/reference.rb', line 87 def valid? solve true rescue InvalidReferenceError false end |
#value ⇒ Object
Returns the referenced object value.
126 127 128 |
# File 'lib/origami/reference.rb', line 126 def value solve.value end |