Sha256: 5e9c6d748fff9340a5a8580260b46afa7cc0af60cb5e6c33744233bd54433fee

Contents?: true

Size: 1.66 KB

Versions: 17

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true
require 'active_support/core_ext/hash/compact'
require 'video_embed'

module Dato
  module Local
    module FieldType
      class Video
        attr_reader :url
        attr_reader :thumbnail_url
        attr_reader :title
        attr_reader :width
        attr_reader :height
        attr_reader :provider
        attr_reader :provider_url
        attr_reader :provider_uid

        def self.parse(value, _repo)
          new(
            value[:url],
            value[:thumbnail_url],
            value[:title],
            value[:width],
            value[:height],
            value[:provider],
            value[:provider_url],
            value[:provider_uid]
          )
        end

        def initialize(
          url,
          thumbnail_url,
          title,
          width,
          height,
          provider,
          provider_url,
          provider_uid
        )
          @url            = url
          @thumbnail_url  = thumbnail_url
          @title          = title
          @width          = width
          @height         = height
          @provider       = provider
          @provider_url   = provider_url
          @provider_uid   = provider_uid
        end

        def iframe_embed(width = nil, height = nil)
          VideoEmbed.embed(url, { width: width, height: height }.compact)
        end

        def to_hash
          {
            url: url,
            thumbnail_url: thumbnail_url,
            title: title,
            width: width,
            height: height,
            provider: provider,
            provider_url: provider_url,
            provider_uid: provider_uid
          }
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
dato-0.3.2 lib/dato/local/field_type/video.rb
dato-0.3.1 lib/dato/local/field_type/video.rb
dato-0.3.0 lib/dato/local/field_type/video.rb
dato-0.2.7 lib/dato/local/field_type/video.rb
dato-0.2.6 lib/dato/local/field_type/video.rb
dato-0.2.4 lib/dato/local/field_type/video.rb
dato-0.1.31 lib/dato/local/field_type/video.rb
dato-0.1.30 lib/dato/local/field_type/video.rb
dato-0.1.29 lib/dato/local/field_type/video.rb
dato-0.1.28 lib/dato/local/field_type/video.rb
dato-0.1.27 lib/dato/local/field_type/video.rb
dato-0.1.26 lib/dato/local/field_type/video.rb
dato-0.1.25 lib/dato/local/field_type/video.rb
dato-0.1.24 lib/dato/local/field_type/video.rb
dato-0.1.23 lib/dato/local/field_type/video.rb
dato-0.1.22 lib/dato/local/field_type/video.rb
dato-0.1.21 lib/dato/local/field_type/video.rb