Module: Html2rss::Html::ArticleRules::Category
- Defined in:
- lib/html2rss/html/article_rules/category.rb
Overview
Shared category term vocabulary and text accumulation (DOM walk stays in adapters).
Constant Summary collapse
- CATEGORY_TERMS =
Class/data attribute tokens that mark category metadata (not layout words).
%w[ category categories tag tags topic topics theme themes subject subjects ].freeze
- TERM_SET =
Frozen set for token membership checks.
CATEGORY_TERMS.to_set.freeze
- CLASS_TOKEN_SPLIT =
Hyphen/underscore/BEM separators inside a single CSS class token.
/[-_]+/
Class Method Summary collapse
- .add_split_text!(categories, text, title: nil) ⇒ void
- .add_text!(categories, text, title: nil) ⇒ void
- .attr_name_match?(name) ⇒ Boolean
- .class_match?(class_attr) ⇒ Boolean
Class Method Details
.add_split_text!(categories, text, title: nil) ⇒ void
This method returns an undefined value.
53 54 55 56 57 |
# File 'lib/html2rss/html/article_rules/category.rb', line 53 def add_split_text!(categories, text, title: nil) return unless text text.split(/\n+/).each { |line| add_text!(categories, line, title:) } end |
.add_text!(categories, text, title: nil) ⇒ void
This method returns an undefined value.
41 42 43 44 45 46 |
# File 'lib/html2rss/html/article_rules/category.rb', line 41 def add_text!(categories, text, title: nil) value = text.to_s.strip return if value.empty? || !Description.keep?(value, title:, type_chips: false) categories.add(value) end |
.attr_name_match?(name) ⇒ Boolean
25 26 27 |
# File 'lib/html2rss/html/article_rules/category.rb', line 25 def attr_name_match?(name) TERM_SET.include?(normalize_attr_name(name)) end |
.class_match?(class_attr) ⇒ Boolean
32 33 34 |
# File 'lib/html2rss/html/article_rules/category.rb', line 32 def class_match?(class_attr) class_attr.to_s.split(/\s+/).any? { |token| class_token_match?(token) } end |