Class: Pdfrb::Annotation::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/annotation/base.rb

Overview

Base annotation builder. Subclasses override subtype and default_fields to provide type-specific defaults. Each subclass calls register_as at load time.

Class Method Summary collapse

Class Method Details

.create(document:, page:, rect:, **opts) ⇒ Object

Create the annotation and attach it to the page's /Annots.



22
23
24
25
26
27
# File 'lib/pdfrb/annotation/base.rb', line 22

def create(document:, page:, rect:, **opts)
  dict = base_dict(page: page, rect: rect, **opts).merge!(default_fields).merge!(type_overrides(opts))
  annot = document.add(dict, type: Pdfrb::Model::Type::Annotation)
  attach_to_page(page, annot)
  annot
end

.default_fieldsHash

Extra fields to merge into the annotation dict.

Returns:

  • (Hash)


17
18
19
# File 'lib/pdfrb/annotation/base.rb', line 17

def default_fields
  {}
end

.register_as(symbol = subtype) ⇒ Object

Register this class in the Annotation registry.



30
31
32
33
# File 'lib/pdfrb/annotation/base.rb', line 30

def register_as(symbol = subtype)
  Annotation.register(symbol, self)
  self
end

.subtypeSymbol

Returns the /Subtype value (e.g. :Link).

Returns:

  • (Symbol)

    the /Subtype value (e.g. :Link).

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/pdfrb/annotation/base.rb', line 11

def subtype
  raise NotImplementedError, "#{self} must define subtype"
end