module Coco class YoutubeEmbed < Coco::Component def initialize(url:, **kwargs) @url = url end def video_id youtube_url = /youtube.com\/(watch\?v=|v\/)([^&]+)/.match(@url) youtube_url[2] if youtube_url end def src "https://www.youtube.com/embed/#{video_id}" end end end