Class: Html2rss::Config::Selectors
- Inherits:
-
Object
- Object
- Html2rss::Config::Selectors
- Defined in:
- lib/html2rss/config/selectors.rb
Overview
Holds the configurations of the selectors.
Defined Under Namespace
Classes: Selector
Constant Summary collapse
- ITEMS_SELECTOR_NAME =
:items
Instance Method Summary collapse
- #category_selector_names ⇒ Set<Symbol>
- #guid_selector_names ⇒ Set<Symbol>
-
#initialize(config) ⇒ Selectors
constructor
A new instance of Selectors.
- #item_selector_names ⇒ Set<Symbol>
- #items_order ⇒ Symbol?
- #selector(name) ⇒ Selector
- #selector?(name) ⇒ true, false
-
#selector_string(name) ⇒ String
Returns the CSS/XPath selector.
Constructor Details
#initialize(config) ⇒ Selectors
Returns a new instance of Selectors.
15 16 17 18 |
# File 'lib/html2rss/config/selectors.rb', line 15 def initialize(config) validate_config(config) @config = config end |
Instance Method Details
#category_selector_names ⇒ Set<Symbol>
38 39 40 |
# File 'lib/html2rss/config/selectors.rb', line 38 def category_selector_names selector_keys_for(:categories) end |
#guid_selector_names ⇒ Set<Symbol>
44 45 46 |
# File 'lib/html2rss/config/selectors.rb', line 44 def guid_selector_names selector_keys_for(:guid, default: :title_or_description) end |
#item_selector_names ⇒ Set<Symbol>
59 60 61 |
# File 'lib/html2rss/config/selectors.rb', line 59 def item_selector_names @item_selector_names ||= config.keys.reject { |key| key == ITEMS_SELECTOR_NAME }.to_set end |
#items_order ⇒ Symbol?
65 66 67 |
# File 'lib/html2rss/config/selectors.rb', line 65 def items_order config.dig(ITEMS_SELECTOR_NAME, :order)&.to_sym end |
#selector(name) ⇒ Selector
30 31 32 33 34 |
# File 'lib/html2rss/config/selectors.rb', line 30 def selector(name) raise ArgumentError, "invalid item's selector name: #{name}" unless selector?(name) Selector.new(config[name]) end |
#selector?(name) ⇒ true, false
23 24 25 |
# File 'lib/html2rss/config/selectors.rb', line 23 def selector?(name) name != ITEMS_SELECTOR_NAME && item_selector_names.include?(name) end |