Class: Spina::Embeds::Youtube

Inherits:
Base
  • Object
show all
Defined in:
app/models/spina/embeds/youtube.rb

Constant Summary collapse

REGEX =
/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|shorts\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/

Instance Method Summary collapse

Methods included from TrixConversion

#to_trix_attachment, #wrap_with_embed_tag

Methods included from Spina::Embeddable

#initialize, #to_fields_path

Instance Method Details

#idObject



13
14
15
# File 'app/models/spina/embeds/youtube.rb', line 13

def id
  REGEX.match(url).try(:[], 1)
end

#remote_titleObject

Get title from Youtube API (remote call)



18
19
20
# File 'app/models/spina/embeds/youtube.rb', line 18

def remote_title
  get_youtube_json&.dig("title")
end

#to_trix_partial_pathObject



22
23
24
# File 'app/models/spina/embeds/youtube.rb', line 22

def to_trix_partial_path
  "spina/embeds/youtubes/thumbnail"
end