Class: Yt::Models::URL
- Inherits:
-
Object
- Object
- Yt::Models::URL
- Defined in:
- lib/yt/models/url.rb
Overview
Provides methods to identify YouTube resources from names or URLs.
Instance Method Summary collapse
-
#id ⇒ <String, nil>
The ID of the YouTube resource matching the URL.
-
#initialize(text) ⇒ URL
constructor
A new instance of URL.
-
#kind ⇒ Symbol
Possible values are:
:playlist
,:video
,:channel
, and +:unknown:. -
#resource(options = {}) ⇒ <Yt::Channel>
The resource associated with the URL.
Constructor Details
#initialize(text) ⇒ URL
Returns a new instance of URL.
15 16 17 |
# File 'lib/yt/models/url.rb', line 15 def initialize(text) @text = text.to_s.strip end |
Instance Method Details
#id ⇒ <String, nil>
Returns the ID of the YouTube resource matching the URL.
26 27 28 |
# File 'lib/yt/models/url.rb', line 26 def id Resource.new(url: @text).id end |
#kind ⇒ Symbol
Possible values are: :playlist
, :video
, :channel
, and +:unknown:.
21 22 23 |
# File 'lib/yt/models/url.rb', line 21 def kind Resource.new(url: @text).kind.to_sym end |
#resource(options = {}) ⇒ <Yt::Channel>
Returns the resource associated with the URL.
31 32 33 34 35 36 37 38 |
# File 'lib/yt/models/url.rb', line 31 def resource( = {}) @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 .merge(id: id) end |