class Youframe::Builder

Public Class Methods

new(url, options = {}) click to toggle source
# File lib/youframe/builder.rb, line 3
def initialize(url, options = {})
        @url = url
        @width = options[:width] || 560
        @height = options[:height] || 315
        @start_time = options[:start_time]
        @frameborder = options[:frameborder] || 0

        @allowfullscreen = options.fetch(:allowfullscreen, true)
        @accelerometer = options.fetch(:accelerometer, true)
        @autoplay = options.fetch(:autoplay, true)
        @encrypted_media = options.fetch(:encrypted_media, true)
        @gyroscope = options.fetch(:gyroscope, true)
        @picture_in_picture = options.fetch(:picture_in_picture, true)
end

Public Instance Methods

allow_full_screen() click to toggle source
# File lib/youframe/builder.rb, line 40
def allow_full_screen
        @allowfullscreen ? "allowfullscreen" : nil
end
allow_str() click to toggle source
# File lib/youframe/builder.rb, line 30
def allow_str
        allow_str = ''
        allow_str += 'accelerometer; ' if @accelerometer
        allow_str += 'autoplay; ' if @autoplay
        allow_str += 'encrypted-media; ' if @encrypted_media
        allow_str += 'gyroscope; ' if @gyroscope
        allow_str += 'picture-in-picture' if @picture_in_picture
        allow_str
end
generate() click to toggle source
# File lib/youframe/builder.rb, line 44
def generate
        tag = "<iframe width='#{@width}' height='#{@height}' src='#{url}' frameborder='#{@frameborder}' allow='#{allow_str}'#{allow_full_screen}></iframe>"
        tag
end
url() click to toggle source
# File lib/youframe/builder.rb, line 18
def url
        id = ""
        if @url.match(/youtu.be/)
                id = @url.split(/youtu.be\//)[-1].split("?t")[0]
        elsif @url.match(/www.youtube.com\/watch?/)
                id = @url.split(/watch\?v=/)[-1].split("&t=")[0]
        end
        @url = "https://www.youtube.com/embed/#{id}"

        @start_time.nil? ? @url : @url + "?start=#{@start_time}"
end