Class: Yt::Models::Annotation
- Inherits:
-
Object
- Object
- Yt::Models::Annotation
- Defined in:
- lib/yt/models/annotation.rb
Overview
Provides methods to interact with YouTube annotations.
Instance Method Summary collapse
-
#above?(y) ⇒ Boolean
Whether the text box surrounding the annotation is completely in the top y% of the video frame.
-
#below?(y) ⇒ Boolean
Whether the text box surrounding the annotation is completely in the bottom y% of the video frame.
-
#has_invideo_programming? ⇒ Boolean
Whether the annotation is an “InVideo Programming”.
-
#has_link_to_playlist? ⇒ Boolean
Whether the annotation includes a link to a playlist, or to a video embedded in a playlist.
-
#has_link_to_same_window? ⇒ Boolean
Whether the annotation includes a link that will open in the current browser window.
-
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Whether the annotation includes a link to subscribe.
-
#has_link_to_video?(options = {}) ⇒ Boolean
Whether the annotation includes a link to a video, either directly in the text, or as an “Invideo featured video”.
-
#initialize(options = {}) ⇒ Annotation
constructor
A new instance of Annotation.
-
#starts_after?(seconds) ⇒ Boolean
have the timestamp in the region, but in the “data” field.
-
#starts_before?(seconds) ⇒ Boolean
have the timestamp in the region, but in the “data” field.
Constructor Details
#initialize(options = {}) ⇒ Annotation
YouTube API V3 does not provide access to video annotations, therefore the XML endpoint is used to retrieve them and its response is passed to the Annotation initializer.
Returns a new instance of Annotation.
11 12 13 |
# File 'lib/yt/models/annotation.rb', line 11 def initialize( = {}) @data = [:data] end |
Instance Method Details
#above?(y) ⇒ Boolean
Returns whether the text box surrounding the annotation is completely in the top y% of the video frame.
18 19 20 |
# File 'lib/yt/models/annotation.rb', line 18 def above?(y) top && top < y end |
#below?(y) ⇒ Boolean
Returns whether the text box surrounding the annotation is completely in the bottom y% of the video frame.
25 26 27 |
# File 'lib/yt/models/annotation.rb', line 25 def below?(y) bottom && bottom > y end |
#has_invideo_programming? ⇒ Boolean
Returns whether the annotation is an “InVideo Programming”.
53 54 55 |
# File 'lib/yt/models/annotation.rb', line 53 def has_invideo_programming? type == 'promotion' || type == 'branding' end |
#has_link_to_playlist? ⇒ Boolean
Returns whether the annotation includes a link to a playlist, or to a video embedded in a playlist.
42 43 44 |
# File 'lib/yt/models/annotation.rb', line 42 def has_link_to_playlist? link_class == '2' || text.include?('&list=') end |
#has_link_to_same_window? ⇒ Boolean
Returns whether the annotation includes a link that will open in the current browser window.
48 49 50 |
# File 'lib/yt/models/annotation.rb', line 48 def has_link_to_same_window? link_target == 'current' end |
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Returns whether the annotation includes a link to subscribe.
30 31 32 |
# File 'lib/yt/models/annotation.rb', line 30 def has_link_to_subscribe?( = {}) # TODO: options for which videos link_class == '5' end |
#has_link_to_video?(options = {}) ⇒ Boolean
Returns whether the annotation includes a link to a video, either directly in the text, or as an “Invideo featured video”.
36 37 38 |
# File 'lib/yt/models/annotation.rb', line 36 def has_link_to_video?( = {}) # TODO: options for which videos link_class == '1' || type == 'promotion' end |
#starts_after?(seconds) ⇒ Boolean
This is broken for invideo programming, because they do not
have the timestamp in the region, but in the “data” field
62 63 64 |
# File 'lib/yt/models/annotation.rb', line 62 def starts_after?(seconds) .first > seconds if .any? end |
#starts_before?(seconds) ⇒ Boolean
This is broken for invideo programming, because they do not
have the timestamp in the region, but in the “data” field
71 72 73 |
# File 'lib/yt/models/annotation.rb', line 71 def starts_before?(seconds) .first < seconds if .any? end |