module Coco module Embeds class Youtube < Coco::Component component_name :youtube_embed 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 end