Class: Html2rss::AutoSource::Scraper::MetaOembed
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Scraper::MetaOembed
- Includes:
- Enumerable
- Defined in:
- lib/html2rss/auto_source/scraper/meta_oembed.rb
Overview
Scrapes OpenGraph meta tags and oEmbed JSON descriptors from HTML pages.
Constant Summary collapse
- OG_META_SELECTOR =
Selector for OpenGraph meta tags.
'meta[property^="og:"], meta[property^="article:"], meta[name^="twitter:"]'- OEMBED_LINK_SELECTOR =
Selector for oEmbed JSON link tag.
'link[rel="alternate"][type="application/json+oembed"][href]'
Class Method Summary collapse
-
.articles?(parsed_body) ⇒ Boolean
Whether OpenGraph tags or oEmbed link exist.
-
.options_key ⇒ Symbol
Scraper config key.
Instance Method Summary collapse
-
#each {|article| ... } ⇒ Enumerator, void
Yields normalized article hash extracted from OpenGraph meta tags and optional oEmbed data.
- #initialize(parsed_body, url:, request_session: nil, **_opts) ⇒ void constructor
Constructor Details
#initialize(parsed_body, url:, request_session: nil, **_opts) ⇒ void
53 54 55 56 57 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 53 def initialize(parsed_body, url:, request_session: nil, **_opts) @parsed_body = parsed_body @url = Html2rss::Url.from_absolute(url) @request_session = request_session end |
Class Method Details
.articles?(parsed_body) ⇒ Boolean
Returns whether OpenGraph tags or oEmbed link exist.
39 40 41 42 43 44 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 39 def articles?(parsed_body) return false unless parsed_body !parsed_body.at_css('meta[property="og:title"]').nil? || !parsed_body.at_css(OEMBED_LINK_SELECTOR).nil? end |
.options_key ⇒ Symbol
Returns scraper config key.
34 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 34 def self. = :meta_oembed |
Instance Method Details
#each {|article| ... } ⇒ Enumerator, void
Yields normalized article hash extracted from OpenGraph meta tags and optional oEmbed data.
64 65 66 67 68 69 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 64 def each return enum_for(:each) unless block_given? article = build_article yield article if article end |