Sha256: 1dc1e0f2f260a98150c4c420d4cf0644084cfff2dca1290d1b908ae7d2b20651

Contents?: true

Size: 814 Bytes

Versions: 11

Compression:

Stored size: 814 Bytes

Contents

require 'yt/annotations/card'

module Yt
  module Annotations
    # A Featured annotation is similar to a card, except that it displays in
    # the bottom-left corner and only shows if no cards are present.
    class Featured < Card
    private
      def text_in(json)
        json.values_at('text_line_1', 'text_line_2').join(': ')
      end

      def ends_at_in(data)
        data['end_ms'] / 1000.0
      end

      def to_link(data, json)
        return unless url = data.fetch('action', {})['url']
        new_window = url['target'] != 'current'
        {url: url['value'], new_window: new_window, type: link_type(json)}
      end

      def link_type(json)
        if json['playlist_length']
          :playlist
        elsif json['video_duration']
          :video
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
yt-annotations-1.4.2 lib/yt/annotations/featured.rb
yt-annotations-1.4.1 lib/yt/annotations/featured.rb
yt-annotations-1.4.0 lib/yt/annotations/featured.rb
yt-annotations-1.3.2 lib/yt/annotations/featured.rb
yt-annotations-1.3.1 lib/yt/annotations/featured.rb
yt-annotations-1.3.0 lib/yt/annotations/featured.rb
yt-annotations-1.2.3 lib/yt/annotations/featured.rb
yt-annotations-1.2.2 lib/yt/annotations/featured.rb
yt-annotations-1.2.1 lib/yt/annotations/featured.rb
yt-annotations-1.2.0 lib/yt/annotations/featured.rb
yt-annotations-1.1.0 lib/yt/annotations/featured.rb