Class: Obp::Access::Renderer::Elements::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/obp/access/elements/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, metas:, node:) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/obp/access/elements/base.rb', line 10

def initialize(document:, metas:, node:)
  @document = document
  @metas = metas
  @node = node
end

Instance Attribute Details

#documentObject (readonly)

Elements are rendered using the NISO STS spec: https://www.niso-sts.org/TagLibrary/niso-sts-TL-1-2-html/index.html



8
9
10
# File 'lib/obp/access/elements/base.rb', line 8

def document
  @document
end

#metasObject (readonly)

Elements are rendered using the NISO STS spec: https://www.niso-sts.org/TagLibrary/niso-sts-TL-1-2-html/index.html



8
9
10
# File 'lib/obp/access/elements/base.rb', line 8

def metas
  @metas
end

#nodeObject (readonly)

Elements are rendered using the NISO STS spec: https://www.niso-sts.org/TagLibrary/niso-sts-TL-1-2-html/index.html



8
9
10
# File 'lib/obp/access/elements/base.rb', line 8

def node
  @node
end

Class Method Details

.classesObject



16
17
18
# File 'lib/obp/access/elements/base.rb', line 16

def self.classes
  nil
end

Instance Method Details

#match_node?Boolean

Subset match: OBP varies class order and adds marker classes (e.g. "commentable"), so a node matches when it carries at least the registered classes, regardless of order or extras.

Returns:

  • (Boolean)


23
24
25
# File 'lib/obp/access/elements/base.rb', line 23

def match_node?
  (self.class.classes - node.classes).empty?
end

#render(target:) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/obp/access/elements/base.rb', line 27

def render(target:)
  # Top-level nodes without their own insertion target (e.g. a
  # floating sts-p between sections) default to the body.
  effective_target = insertion_target || target || "body"
  effective_target = "#{effective_target}#{path_suffix}" if path_suffix
  document.at(effective_target).public_send(insert_method, to_xml)
end