Class: Yt::Models::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/yt/models/resource.rb

Direct Known Subclasses

Channel, Comment, CommentThread, Playlist, PlaylistItem, Video

Constant Summary collapse

PLAYLIST_PATTERNS =

Returns patterns matching URLs of YouTube playlists.

Returns:

  • (Array<Regexp>)

    patterns matching URLs of YouTube playlists.

[
   %r{^(?:https?://)?(?:www\.)?youtube\.com/playlist/?\?list=(?<id>[a-zA-Z0-9_-]+)},
]
VIDEO_PATTERNS =

Returns patterns matching URLs of YouTube videos.

Returns:

  • (Array<Regexp>)

    patterns matching URLs of YouTube videos.

[
  %r{^(?:https?://)?(?:www\.)?youtube\.com/watch\?v=(?<id>[a-zA-Z0-9_-]{11})},
  %r{^(?:https?://)?(?:www\.)?youtu\.be/(?<id>[a-zA-Z0-9_-]{11})},
  %r{^(?:https?://)?(?:www\.)?youtube\.com/embed/(?<id>[a-zA-Z0-9_-]{11})},
  %r{^(?:https?://)?(?:www\.)?youtube\.com/v/(?<id>[a-zA-Z0-9_-]{11})},
]
CHANNEL_PATTERNS =

Returns patterns matching URLs of YouTube channels.

Returns:

  • (Array<Regexp>)

    patterns matching URLs of YouTube channels.

[
  %r{^(?:https?://)?(?:www\.)?youtube\.com/channel/(?<id>UC[a-zA-Z0-9_-]{22})},
  %r{^(?:https?://)?(?:www\.)?youtube\.com/(?<format>c/|user/)?(?<name>[a-zA-Z0-9_-]+)}
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)



15
16
17
# File 'lib/yt/models/resource.rb', line 15

def id
  @id ||= @match['id'] || fetch_channel_id
end

#privacy_statusString (readonly)

Returns the privacy status of the resource. Possible values are: ‘private’, ‘public’, ‘unlisted’.

Returns:

  • (String)

    the privacy status of the resource. Possible values are: ‘private’, ‘public’, ‘unlisted’.



26
# File 'lib/yt/models/resource.rb', line 26

delegate :privacy_status, to: :status

Instance Method Details

#private?Boolean

Returns whether the resource is private.

Returns:

  • (Boolean)

    whether the resource is private.



34
35
36
# File 'lib/yt/models/resource.rb', line 34

def private?
  privacy_status == 'private'
end

#public?Boolean

Returns whether the resource is public.

Returns:

  • (Boolean)

    whether the resource is public.



29
30
31
# File 'lib/yt/models/resource.rb', line 29

def public?
  privacy_status == 'public'
end

#unlisted?Boolean

Returns whether the resource is unlisted.

Returns:

  • (Boolean)

    whether the resource is unlisted.



39
40
41
# File 'lib/yt/models/resource.rb', line 39

def unlisted?
  privacy_status == 'unlisted'
end