Module: Integral::Video::Embed::Bootstrap

Defined in:
lib/integral/video/embed/bootstrap.rb

Constant Summary collapse

PROPORTIONS =
["16by9", "4by3"]

Class Method Summary collapse

Class Method Details

.html(uid, provider:, hash: nil, proportions: "16by9") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/integral/video/embed/bootstrap.rb', line 11

def html(uid, provider:, hash: nil, proportions: "16by9")
  fail ArgumentError, "`uid` must be provided, you passed #{uid.inspect}"              if uid.nil? || uid == ""
  fail ArgumentError, "`provider` must be provided, you passed #{provider.inspect}"    if provider.nil? || provider == ""
  fail ArgumentError, "`proportions` must be provided to embed via Bootstrap strategy" if proportions.nil? || proportions == ""
  fail ArgumentError, "`proportions` must be one of #{PROPORTIONS.inspect}" unless PROPORTIONS.include? proportions
  provider_names = Integral::Video::Provider.names
  fail ArgumentError, "Unkown provider '#{provider}'. Supported are: #{provider_names.inspect}" unless provider_names.include? provider

  src = Integral::Video::Provider.new(provider).iframe_src(uid, hash)
  fail StandardError, "`Integral::Video::Provider` error: `iframe_src` could not be calculated when it must be. Seems like you will have to manually correct this gem's code. Such is open source." unless src

  "    <div class=\"embed-responsive embed-responsive-\#{proportions}\">\n      <iframe class=\"embed-responsive-item\" src=\"\#{src}\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>\n    </div>\n  HEREDOC\nend\n"