class Yt::Annotations::Note

A Note annotation is just a basic annotation with text, start/end time and an optional link. It's shaped like a Post-It with a curved corner.

Public Class Methods

new(data = {}) click to toggle source

@param [Hash] data the Hash representation of the XML data returned by

YouTube for each annotation of a video.
# File lib/yt/annotations/note.rb, line 10
def initialize(data = {})
  @text = data['TEXT']
  @starts_at = to_seconds regions_of(data)[0]['t']
  @ends_at = to_seconds regions_of(data)[1]['t']
  @link = to_link data.fetch('action', {})['url']
end

Private Instance Methods

regions_of(data) click to toggle source
# File lib/yt/annotations/note.rb, line 19
def regions_of(data)
  data['segment']['movingRegion']['rectRegion']
end
to_seconds(timestamp) click to toggle source
# File lib/yt/annotations/note.rb, line 23
def to_seconds(timestamp)
  timestamp.split(':').map(&:to_f).inject(0) {|sum, n| 60 * sum + n}
end