Class: Pdfrb::Model::Object

Inherits:
Object
  • Object
show all
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

Cos::Dictionary, PdfArray

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#documentObject (readonly)

Returns the value of attribute document.



21
22
23
# File 'lib/pdfrb/model/object.rb', line 21

def document
  @document
end

#genObject (readonly)

Returns the value of attribute gen.



21
22
23
# File 'lib/pdfrb/model/object.rb', line 21

def gen
  @gen
end

#oidObject (readonly)

Returns the value of attribute oid.



21
22
23
# File 'lib/pdfrb/model/object.rb', line 21

def oid
  @oid
end

#valueObject (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_typeObject



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

#derefObject

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).

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


37
38
39
# File 'lib/pdfrb/model/object.rb', line 37

def must_be_indirect?
  false
end

#pdf_typeObject

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