Class: ProductTours::VideoResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/product_tours/video_resolver.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

YOUTUBE_HOSTS =
%w[youtube.com www.youtube.com m.youtube.com youtu.be youtube-nocookie.com
www.youtube-nocookie.com].freeze
VIMEO_HOSTS =
%w[vimeo.com www.vimeo.com player.vimeo.com].freeze
LOOM_HOSTS =
%w[loom.com www.loom.com].freeze
TELLA_HOSTS =
%w[tella.tv www.tella.tv].freeze
VOOMLY_HOSTS =
%w[share.voomly.com embed.voomly.com app.voomly.com voomly.com www.voomly.com].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ VideoResolver

Returns a new instance of VideoResolver.



31
32
33
# File 'lib/product_tours/video_resolver.rb', line 31

def initialize(url)
  @url = url.to_s.strip
end

Class Method Details

.resolve(url) ⇒ Object



27
28
29
# File 'lib/product_tours/video_resolver.rb', line 27

def self.resolve(url)
  new(url).resolve
end

Instance Method Details

#resolveObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/product_tours/video_resolver.rb', line 35

def resolve
  uri = URI.parse(@url)
  return unless uri.is_a?(URI::HTTPS) && uri.host.present? && uri.userinfo.nil?

  case uri.host.downcase
  when *YOUTUBE_HOSTS then youtube(uri)
  when *VIMEO_HOSTS then vimeo(uri)
  when *LOOM_HOSTS then loom(uri)
  when *TELLA_HOSTS then tella(uri)
  when *VOOMLY_HOSTS then voomly(uri)
  else direct(uri)
  end
rescue URI::InvalidURIError, ArgumentError
  nil
end