Class: Biovision::Components::Content::Oembed::Receiver
- Inherits:
-
Object
- Object
- Biovision::Components::Content::Oembed::Receiver
show all
- Defined in:
- app/lib/biovision/components/content/oembed/receiver.rb
Overview
Default receiver for embedded media
Constant Summary
collapse
- PATTERN =
%r{<oembed url="([^"]+)"></oembed>}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url = '') ⇒ Receiver
Returns a new instance of Receiver.
13
14
15
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 13
def initialize(url = '')
@url = url
end
|
Class Method Details
.[](url) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 18
def self.[](url)
host = URI.parse(url).host
slug = OembedDomain[host]&.receiver_slug
receiver_path = "biovision/components/content/oembed/#{slug}_receiver"
receiver_class = receiver_path.classify.safe_constantize
receiver_class.nil? ? new(url) : receiver_class.new(url)
end
|
.convert(text) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 28
def self.convert(text)
text.gsub(PATTERN) do |fragment|
url = fragment.match(PATTERN)[1].to_s
return '' if url.blank?
receiver = self[url]
receiver.code
end
end
|
.domains ⇒ Object
42
43
44
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 42
def self.domains
%w[]
end
|
.seed ⇒ Object
46
47
48
49
50
51
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 46
def self.seed
receiver_entity = OembedReceiver.find_or_create_by(slug: slug)
domains.each do |domain|
receiver_entity.oembed_domains.create(name: domain)
end
end
|
.slug ⇒ Object
38
39
40
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 38
def self.slug
to_s.demodulize.to_s.underscore.gsub('_receiver', '')
end
|
Instance Method Details
#code ⇒ Object
53
54
55
56
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 53
def code
@link = OembedLink[@url]
@link.code || receive_and_update
end
|
#fallback ⇒ Object
58
59
60
61
|
# File 'app/lib/biovision/components/content/oembed/receiver.rb', line 58
def fallback
attributes = %(rel="external nofollow noreferrer" target="_blank")
%(<a href="#{@url}" #{attributes}>#{URI.parse(@url).host}</a>)
end
|