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:"]'
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
54 55 56 57 58 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 54 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.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 36 def articles?(parsed_body) return false unless parsed_body !parsed_body.at_css('meta[property="og:title"]').nil? || ::Html2rss::Html::Probe.alternate_links( parsed_body, rel: 'alternate', mime: ::Html2rss::Html::Probe::APPLICATION_JSON_OEMBED ).any? end |
.options_key ⇒ Symbol
Returns scraper config key.
31 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 31 def self. = :meta_oembed |
Instance Method Details
#each {|article| ... } ⇒ Enumerator, void
Yields normalized article hash extracted from OpenGraph meta tags and optional oEmbed data.
65 66 67 68 69 70 |
# File 'lib/html2rss/auto_source/scraper/meta_oembed.rb', line 65 def each return enum_for(:each) unless block_given? article = build_article yield article if article end |