class Yt::Annotations::Card
A Card
annotation is different from a Note
annotation in the way data is represented in the XML under a new 'data' key with JSON-formatted content.
Public Class Methods
new(data = {})
click to toggle source
@param [Hash] data the Hash representation of the XML data returned by
YouTube for each card of a video.
# File lib/yt/annotations/card.rb, line 10 def initialize(data = {}) json = JSON.parse data['data'] @text = text_in json @starts_at = json['start_ms'] / 1000.0 @ends_at = ends_at_in json @link = to_link data, json end
Private Instance Methods
ends_at_in(json)
click to toggle source
# File lib/yt/annotations/card.rb, line 24 def ends_at_in(json) (json['start_ms'] + json['teaser_duration_ms']) / 1000.0 end
text_in(json)
click to toggle source
# File lib/yt/annotations/card.rb, line 20 def text_in(json) json['teaser_text'] end
to_link(data, json)
click to toggle source
# File lib/yt/annotations/card.rb, line 28 def to_link(data, json) link_type = case json['card_type'] when 'collaborator' then :channel when 'playlist' then :playlist when 'video' then :video when 'simple' then :website end {url: json['url'], new_window: true, type: link_type} end