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. rubocop:disable Metrics/ClassLength -- leftover re-extract stays with field extractors
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, time_zone: 'UTC') ⇒ 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, time_zone: 'UTC') ⇒ ArticleExtractor
constructor
A new instance of ArticleExtractor.
Constructor Details
#initialize(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false, time_zone: 'UTC') ⇒ ArticleExtractor
Returns a new instance of ArticleExtractor.
31 32 33 34 35 36 37 38 39 |
# File 'lib/html2rss/html/article_extractor.rb', line 31 def initialize(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false, time_zone: 'UTC') 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 @time_zone = time_zone end |
Class Method Details
.call(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false, time_zone: 'UTC') ⇒ Hash{Symbol => Object}
Extracts article attributes from a DOM element.
20 21 22 |
# File 'lib/html2rss/html/article_extractor.rb', line 20 def call(article_tag, base_url:, selected_anchor: nil, fallback_anchorless: false, time_zone: 'UTC') new(article_tag, base_url:, selected_anchor:, fallback_anchorless:, time_zone:).call end |
Instance Method Details
#call ⇒ Hash{Symbol => Object}
Returns extracted article attributes.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/html2rss/html/article_extractor.rb', line 42 def call # rubocop:disable Metrics/MethodLength title = extract_title lines = leftover_lines published_at = extract_published_at(lines) source, lines, published_at = parent_card_fields(title, lines, published_at) { title:, url: extract_url, image: extract_image, description: ArticleRules::Description.from_lines(lines, title:), id: generate_id, published_at:, enclosures: extract_enclosures, categories: CategoryExtractor.call(source, title:) } end |