diff --git a/CHANGELOG.md b/CHANGELOG.md index c79485f..b4dfe2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ For more information about changelogs, check [Keep a Changelog](http://keepachangelog.com) and [Vandamme](http://tech-angels.github.io/vandamme). +## 0.1.3 - 2016.02.16 + +* [FEATURE] Add `has_link_to_own_channel?` + ## 0.1.2 - 2016.02.11 * [FEATURE] Add `has_subscribe_annotations?` diff --git a/README.md b/README.md index 5751e3f..4466959 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,6 @@ Yt::Audit.has_brand_anchoring?('rF711XAtrVg', 'Budweiser') # => true Yt::Audit.has_subscribe_annotations?('rF711XAtrVg') # => false +Yt::Audit.has_link_to_own_channel?('rF711XAtrVg') +# => false ``` diff --git a/lib/yt/audit.rb b/lib/yt/audit.rb index 4ef988c..82130f1 100644 --- a/lib/yt/audit.rb +++ b/lib/yt/audit.rb @@ -29,5 +29,15 @@ def self.has_subscribe_annotations?(video_id) annotation.link && annotation.link[:type] == :subscribe end end + + # Audit youtube association of a video + # @param [String] video_id the video to audit. + # @return [Boolean] if the video description has link to its own channel. + def self.has_link_to_own_channel?(video_id) + video = Yt::Video.new(id: video_id) + video.description.split(' ') + .select {|word| Yt::URL.new(word).kind == :channel } + .any? {|link| Yt::Channel.new(url: link).id == video.channel_id } + end end end diff --git a/lib/yt/audit/version.rb b/lib/yt/audit/version.rb index 89cf30f..94a75e2 100644 --- a/lib/yt/audit/version.rb +++ b/lib/yt/audit/version.rb @@ -1,5 +1,5 @@ module Yt module Audit - VERSION = "0.1.2" + VERSION = "0.1.3" end end diff --git a/test/yt/audit_test.rb b/test/yt/audit_test.rb index d0cd25f..11783f0 100644 --- a/test/yt/audit_test.rb +++ b/test/yt/audit_test.rb @@ -34,4 +34,12 @@ def test_has_subscribe_annotations def test_does_not_have_subscribe_annotations assert_equal false, Yt::Audit.has_subscribe_annotations?(@bad_video_id) end + + def test_has_youtube_association + assert_equal true, Yt::Audit.has_link_to_own_channel?(@good_video_id) + end + + def test_does_not_have_youtube_association + assert_equal false, Yt::Audit.has_link_to_own_channel?(@bad_video_id) + end end