Class: Yt::Models::Description

Inherits:
String
  • Object
show all
Defined in:
lib/yt/models/description.rb

Overview

Provides read-only access to the description of a YouTube resource. Resources with descriptions are: videos and channels.

description = Yt::Description.new ‘Fullscreen provides a suite of end-to-end YouTube tools and services to many of the world’s leading brands and media companies.’ description.to_s.slice(0,19) # => ‘Fullscreen provides’ description.length # => 127

Instance Method Summary collapse

Instance Method Details

Returns whether the description includes a YouTube channel URL

description = Yt::Description.new ‘Link to channel: youtube.com/fullscreen’ description.has_link_to_channel? #=> true

Returns:

  • (Boolean)

    Whether the description includes a link to a channel



37
38
39
40
41
# File 'lib/yt/models/description.rb', line 37

def has_link_to_channel?(options = {}) # TODO: which channel
  # TODO: might take as an option WHICH channel to link to
  # in order to check if it's my own channel
  links.any?{|link| link.kind == :channel}
end

Returns whether the description includes a YouTube playlist URL

description = Yt::Description.new ‘Link to playlist: youtube.com/playlist?list=LLxO1tY8h1AhOz0T4ENwmpow’ description.has_link_to_playlist? #=> true

Returns:

  • (Boolean)

    Whether the description includes a link to a playlist



65
66
67
# File 'lib/yt/models/description.rb', line 65

def has_link_to_playlist?
  links.any?{|link| link.kind == :playlist}
end

Returns whether the description includes a YouTube subscription URL

description = Yt::Description.new ‘Link to subscribe: youtube.com/subscription_center?add_user=fullscreen’ description.has_link_to_subscribe? #=> true

Returns:

  • (Boolean)

    Whether the description includes a link to subscribe



51
52
53
54
55
# File 'lib/yt/models/description.rb', line 51

def has_link_to_subscribe?(options = {}) # TODO: which channel
  # TODO: might take as an option WHICH channel to subscribe to
  # in order to check if it's my own channel
  links.any?{|link| link.kind == :subscription}
end

Returns whether the description includes a YouTube video URL

description = Yt::Description.new ‘Link to video: youtube.com/watch?v=MESycYJytkU’ description.has_link_to_video? #=> true

Returns:

  • (Boolean)

    Whether the description includes a link to a video



23
24
25
26
27
# File 'lib/yt/models/description.rb', line 23

def has_link_to_video?
  # TODO: might take as an option WHICH video to link to
  # in order to check if it's my own video
  links.any?{|link| link.kind == :video}
end