Class: Pdfrb::Model::Object
- Inherits:
-
Object
- Object
- Pdfrb::Model::Object
- Defined in:
- lib/pdfrb/model/object.rb
Overview
Base wrapper for every PDF value (direct or indirect). Carries the indirect-reference metadata (oid, gen) and a back-reference to the owning Document for lazy resolution.
The wrapped value is the raw Ruby representation:
Boolean -> true / false
Integer -> Integer
Real -> Float
Name -> Symbol
String -> String (UTF-8 for text, BINARY for bytes)
Null -> nil
Array -> Array or PdfArray
Dict -> Hash or Dictionary
Stream -> Stream (subclass of Dictionary)
Ref -> Reference
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#gen ⇒ Object
readonly
Returns the value of attribute gen.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.define_type(type) ⇒ Object
Statically declare the /Type value for this class.
- .pdf_type ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#deref ⇒ Object
Resolve a Reference; pass-through for everything else.
-
#indirect? ⇒ Boolean
True when this object is referenced indirectly (oid > 0).
-
#initialize(value, oid: 0, gen: 0, document: nil) ⇒ Object
constructor
A new instance of Object.
-
#must_be_indirect? ⇒ Boolean
Overridable.
-
#pdf_type ⇒ Object
The PDF /Type name (e.g. :Catalog).
Constructor Details
#initialize(value, oid: 0, gen: 0, document: nil) ⇒ Object
Returns a new instance of Object.
23 24 25 26 27 28 |
# File 'lib/pdfrb/model/object.rb', line 23 def initialize(value, oid: 0, gen: 0, document: nil) @value = value @oid = oid.to_i @gen = gen.to_i @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
21 22 23 |
# File 'lib/pdfrb/model/object.rb', line 21 def document @document end |
#gen ⇒ Object (readonly)
Returns the value of attribute gen.
21 22 23 |
# File 'lib/pdfrb/model/object.rb', line 21 def gen @gen end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
21 22 23 |
# File 'lib/pdfrb/model/object.rb', line 21 def oid @oid end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
21 22 23 |
# File 'lib/pdfrb/model/object.rb', line 21 def value @value end |
Class Method Details
.define_type(type) ⇒ Object
Statically declare the /Type value for this class. Read via
pdf_type. Used by Document#wrap to dispatch.
66 67 68 |
# File 'lib/pdfrb/model/object.rb', line 66 def define_type(type) @pdf_type = type end |
.pdf_type ⇒ Object
70 71 72 |
# File 'lib/pdfrb/model/object.rb', line 70 def pdf_type defined?(@pdf_type) ? @pdf_type : nil end |
Instance Method Details
#==(other) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/pdfrb/model/object.rb', line 56 def ==(other) return false unless other.is_a?(Pdfrb::Model::Object) return object_id == other.object_id if indirect? && other.indirect? @value == other.value end |
#deref ⇒ Object
Resolve a Reference; pass-through for everything else.
42 43 44 |
# File 'lib/pdfrb/model/object.rb', line 42 def deref self end |
#indirect? ⇒ Boolean
True when this object is referenced indirectly (oid > 0).
31 32 33 |
# File 'lib/pdfrb/model/object.rb', line 31 def indirect? @oid > 0 end |
#must_be_indirect? ⇒ Boolean
Overridable. PDF types that must be indirect (Catalog, Pages, ...) override to return true.
37 38 39 |
# File 'lib/pdfrb/model/object.rb', line 37 def must_be_indirect? false end |
#pdf_type ⇒ Object
The PDF /Type name (e.g. :Catalog). Subclasses override via
define_type. Falls back to value for raw dicts.
48 49 50 51 52 53 54 |
# File 'lib/pdfrb/model/object.rb', line 48 def pdf_type own = self.class.pdf_type return own if own return nil unless @value.is_a?(Hash) @value[:Type] end |