Class: Html2rss::Html::ArticleExtractor
- Inherits:
-
Object
- Object
- Html2rss::Html::ArticleExtractor
- Defined in:
- lib/html2rss/html/article_extractor.rb,
lib/html2rss/html/article_extractor/id_generator.rb,
lib/html2rss/html/article_extractor/date_extractor.rb,
lib/html2rss/html/article_extractor/image_extractor.rb,
lib/html2rss/html/article_extractor/heading_extractor.rb,
lib/html2rss/html/article_extractor/category_extractor.rb,
lib/html2rss/html/article_extractor/enclosure_extractor.rb
Overview
ArticleExtractor is responsible for extracting details (headline, url, images, etc.) from an article_tag DOM node. DOM chrome helpers live on Navigator.
Defined Under Namespace
Classes: CategoryExtractor, DateExtractor, EnclosureExtractor, HeadingExtractor, IdGenerator, ImageExtractor
Class Method Summary collapse
-
.call(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) ⇒ Hash{Symbol => Object}
Extracts article attributes from a DOM element.
Instance Method Summary collapse
-
#call ⇒ Hash{Symbol => Object}
Extracted article attributes.
-
#initialize(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) ⇒ ArticleExtractor
constructor
A new instance of ArticleExtractor.
Constructor Details
#initialize(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) ⇒ ArticleExtractor
Returns a new instance of ArticleExtractor.
28 29 30 31 32 33 34 35 |
# File 'lib/html2rss/html/article_extractor.rb', line 28 def initialize(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) raise ArgumentError, 'article_tag is required' unless article_tag @article_tag = article_tag @base_url = base_url @selected_anchor = selected_anchor @fallback_anchorless = fallback_anchorless end |
Class Method Details
.call(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) ⇒ Hash{Symbol => Object}
Extracts article attributes from a DOM element.
18 19 20 |
# File 'lib/html2rss/html/article_extractor.rb', line 18 def call(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false) new(article_tag, base_url:, selected_anchor:, fallback_anchorless:).call end |
Instance Method Details
#call ⇒ Hash{Symbol => Object}
Returns extracted article attributes.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/html2rss/html/article_extractor.rb', line 38 def call { title: extract_title, url: extract_url, image: extract_image, description: extract_description, id: generate_id, published_at: extract_published_at, enclosures: extract_enclosures, categories: extract_categories } end |