Class: HexaPDF::Reference
- Inherits:
-
Object
- Object
- HexaPDF::Reference
- Includes:
- Comparable
- Defined in:
- lib/hexapdf/reference.rb
Overview
A reference to an indirect object.
The PDF syntax allows for references to existing and non-existing indirect objects. Such references are represented with objects of this class.
Note that after initialization changing the object or generation numbers is not possible anymore!
The methods #hash and #eql? are implemented so that objects of this class can be used as hash keys. Furthermore the implementation is compatible to the one of Object, i.e. the hash of a Reference object is the same as the hash of an indirect Object.
See: PDF2.0 s7.3.10, Object
Instance Attribute Summary collapse
-
#gen ⇒ Object
readonly
Returns the generation number of the referenced indirect object.
-
#oid ⇒ Object
readonly
Returns the object number of the referenced indirect object.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares this object to another object.
-
#eql?(other) ⇒ Boolean
(also: #==)
Returns
true
if the other object references the same PDF object as this reference object. -
#hash ⇒ Object
Computes the hash value based on the object and generation numbers.
-
#initialize(oid, gen = 0) ⇒ Reference
constructor
Creates a new Reference with the given object number and, optionally, generation number.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
Returns the object identifier as “oid,gen”.
Constructor Details
#initialize(oid, gen = 0) ⇒ Reference
Creates a new Reference with the given object number and, optionally, generation number.
65 66 67 68 |
# File 'lib/hexapdf/reference.rb', line 65 def initialize(oid, gen = 0) @oid = Integer(oid) @gen = Integer(gen) end |
Instance Attribute Details
#gen ⇒ Object (readonly)
Returns the generation number of the referenced indirect object.
62 63 64 |
# File 'lib/hexapdf/reference.rb', line 62 def gen @gen end |
#oid ⇒ Object (readonly)
Returns the object number of the referenced indirect object.
59 60 61 |
# File 'lib/hexapdf/reference.rb', line 59 def oid @oid end |
Instance Method Details
#<=>(other) ⇒ Object
Compares this object to another object.
If the other object does not respond to oid
or gen
, nil
is returned. Otherwise objects are ordered first by object number and then by generation number.
74 75 76 77 |
# File 'lib/hexapdf/reference.rb', line 74 def <=>(other) return nil unless other.respond_to?(:oid) && other.respond_to?(:gen) (oid == other.oid ? gen <=> other.gen : oid <=> other.oid) end |
#eql?(other) ⇒ Boolean Also known as: ==
Returns true
if the other object references the same PDF object as this reference object.
This is necessary so that Object and Reference objects can be used as interchangable hash keys and can be compared.
83 84 85 |
# File 'lib/hexapdf/reference.rb', line 83 def eql?(other) other.respond_to?(:oid) && oid == other.oid && other.respond_to?(:gen) && gen == other.gen end |
#hash ⇒ Object
Computes the hash value based on the object and generation numbers.
89 90 91 |
# File 'lib/hexapdf/reference.rb', line 89 def hash [oid, gen].hash end |
#inspect ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/hexapdf/reference.rb', line 98 def inspect #:nodoc: "#<#{self.class.name} [#{oid}, #{gen}]>" end |
#to_s ⇒ Object
Returns the object identifier as “oid,gen”.
94 95 96 |
# File 'lib/hexapdf/reference.rb', line 94 def to_s "#{oid} #{gen} R" end |