Class: Html2rss::AutoSource::Scraper::Microformats2
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Scraper::Microformats2
- Includes:
- Enumerable
- Defined in:
- lib/html2rss/auto_source/scraper/microformats2.rb
Overview
Scrapes h-entry objects based on Microformats2 specifications.
Constant Summary collapse
- ENTRY_SELECTOR =
Selector for Microformats2 h-entry containers.
'.h-entry, [class*="h-entry"]'
Class Method Summary collapse
-
.articles?(parsed_body) ⇒ Boolean
Whether Microformats2 h-entry elements exist.
-
.options_key ⇒ Symbol
Scraper config key.
Instance Method Summary collapse
-
#each {|article| ... } ⇒ Enumerator, void
Yields normalized article hashes extracted from h-entry elements.
- #initialize(parsed_body, url:, **_opts) ⇒ void constructor
Constructor Details
#initialize(parsed_body, url:, **_opts) ⇒ void
36 37 38 39 |
# File 'lib/html2rss/auto_source/scraper/microformats2.rb', line 36 def initialize(parsed_body, url:, **_opts) @parsed_body = parsed_body @url = Html2rss::Url.from_absolute(url) end |
Class Method Details
.articles?(parsed_body) ⇒ Boolean
Returns whether Microformats2 h-entry elements exist.
24 25 26 27 28 |
# File 'lib/html2rss/auto_source/scraper/microformats2.rb', line 24 def articles?(parsed_body) return false unless parsed_body !parsed_body.at_css(ENTRY_SELECTOR).nil? end |
.options_key ⇒ Symbol
Returns scraper config key.
19 |
# File 'lib/html2rss/auto_source/scraper/microformats2.rb', line 19 def self. = :microformats2 |
Instance Method Details
#each {|article| ... } ⇒ Enumerator, void
Yields normalized article hashes extracted from h-entry elements.
46 47 48 49 50 51 52 53 |
# File 'lib/html2rss/auto_source/scraper/microformats2.rb', line 46 def each return enum_for(:each) unless block_given? parsed_body.css(ENTRY_SELECTOR).each do |entry| article = build_article(entry) yield article if article end end |