Class: Yt::Models::Snippet

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Snippet

Returns a new instance of Snippet.



6
7
8
# File 'lib/yt/models/snippet.rb', line 6

def initialize(options = {})
  @data = options[:data]
end

Instance Method Details

#descriptionYt::Description

Return the description of a YouTube resource.

Returns:



20
21
22
# File 'lib/yt/models/snippet.rb', line 20

def description
  @description ||= Description.new @data.fetch('description', '')
end

#published_atTime or nil

Return the publication date of a YouTube resource.

Returns:

  • (Time or nil)

    The publication date for the YouTube resource



27
28
29
# File 'lib/yt/models/snippet.rb', line 27

def published_at
  @published_at ||= Time.parse @data['publishedAt']
end

#tagsArray

Note:

YouTube API only includes tags in a resource’s snippet if the resource is a video belonging to the authenticated account.

Return the tags of a YouTube resource.

Returns:

  • (Array)

    An array of Yt::Tag object, one for each tag of the resource.



37
38
39
# File 'lib/yt/models/snippet.rb', line 37

def tags
  @tags ||= @data.fetch 'tags', []
end

#thumbnail_url(size = :default) ⇒ String

Return the URL of a thumbnail image of the YouTube resource.

Returns:

  • (String)

    A URL.



44
45
46
47
# File 'lib/yt/models/snippet.rb', line 44

def thumbnail_url(size = :default)
  @thumbnails ||= @data.fetch 'thumbnails', {}
  @thumbnails.fetch(size.to_s, {})['url']
end

#titleString

Return the title of the YouTube resource.

Returns:

  • (String)

    Title of the YouTube resource



13
14
15
# File 'lib/yt/models/snippet.rb', line 13

def title
  @title ||= @data.fetch 'title', ''
end