class Yt::Models::URL
Provides methods to identify YouTube resources from names or URLs. @see developers.google.com/youtube/v3/docs @example Identify a YouTube video from its short URL:
url = Yt::URL.new 'youtu.be/kawaiiguy' url.id # => 'UC4lU5YG9QDgs0X2jdnt7cdQ' url.resource # => #<Yt::Channel @id=UC4lU5YG9QDgs0X2jdnt7cdQ>
Public Class Methods
Source
# File lib/yt/models/url.rb, line 15 def initialize(text) @text = text.to_s.strip end
@param [String] text the name or URL
of a YouTube resource (in any form).
Public Instance Methods
Source
# File lib/yt/models/url.rb, line 26 def id Resource.new(url: @text).id end
@return [<String, nil>] the ID of the YouTube resource matching the URL
.
Source
# File lib/yt/models/url.rb, line 21 def kind Resource.new(url: @text).kind.to_sym end
@return [Symbol] the kind of YouTube resource matching the URL
. Possible values are: :playlist
, :video
, :channel
, and +:unknown:.
Source
# File lib/yt/models/url.rb, line 31 def resource(options = {}) @resource ||= case kind when :channel then Yt::Channel when :video then Yt::Video when :playlist then Yt::Playlist else raise Yt::Errors::NoItems end.new options.merge(id: id) end
@return [<Yt::Channel>] the resource associated with the URL