Class: Workarea::Storefront::VideoEmbedder

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/storefront/video_embedder.rb,
app/services/workarea/storefront/video_embedder/vimeo.rb,
app/services/workarea/storefront/video_embedder/youtube.rb

Defined Under Namespace

Classes: Vimeo, Youtube

Instance Method Summary collapse

Constructor Details

#initialize(embed_code, options = {}) ⇒ VideoEmbedder

Returns a new instance of VideoEmbedder.



4
5
6
7
# File 'app/services/workarea/storefront/video_embedder.rb', line 4

def initialize(embed_code, options = {})
  @embed_code = Nokogiri::HTML.fragment(embed_code).children.first
  @options = options
end

Instance Method Details

#iframe_attrsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/workarea/storefront/video_embedder.rb', line 9

def iframe_attrs
  attrs = {
    frameborder: '0',
    allowfullscreen: '',
    container_style: "padding-bottom: #{aspect_ratio}%"
  }

  service_embed_code = if vimeo?
    Vimeo.new(@embed_code, @options)
  elsif youtube?
    Youtube.new(@embed_code, @options)
  end

  attrs.merge(service_embed_code.attrs)
end

#vimeo?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/services/workarea/storefront/video_embedder.rb', line 25

def vimeo?
  host =~ /vimeo/ ? true : false
end

#youtube?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/services/workarea/storefront/video_embedder.rb', line 29

def youtube?
  host =~ /youtube/ ? true : false
end