Class: Arclight::EmbedComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/arclight/embed_component.rb

Overview

Render digital object links for a document

Instance Method Summary collapse

Constructor Details

#initialize(document:, presenter:, **kwargs) ⇒ EmbedComponent

Returns a new instance of EmbedComponent.



6
7
8
9
10
11
# File 'app/components/arclight/embed_component.rb', line 6

def initialize(document:, presenter:, **kwargs)
  super

  @document = document
  @presenter = presenter
end

Instance Method Details

#depthObject



29
30
31
# File 'app/components/arclight/embed_component.rb', line 29

def depth
  @document.parents.length || 0
end

#embeddable?(object) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'app/components/arclight/embed_component.rb', line 33

def embeddable?(object)
  exclude_patterns.none? do |pattern|
    object.href =~ pattern
  end
end

#embeddable_resourcesObject



17
18
19
# File 'app/components/arclight/embed_component.rb', line 17

def embeddable_resources
  resources.first(1).select { |object| embeddable?(object) }
end

#exclude_patternsObject



39
40
41
# File 'app/components/arclight/embed_component.rb', line 39

def exclude_patterns
  Arclight::Engine.config.oembed_resource_exclude_patterns
end

#linked_resourcesObject



21
22
23
# File 'app/components/arclight/embed_component.rb', line 21

def linked_resources
  resources - embeddable_resources
end

#render?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/components/arclight/embed_component.rb', line 13

def render?
  resources.any?
end

#resourcesObject



25
26
27
# File 'app/components/arclight/embed_component.rb', line 25

def resources
  @resources ||= @document.digital_objects || []
end