Class: Html2rss::Config::Selectors
- Inherits:
-
Object
- Object
- Html2rss::Config::Selectors
show all
- Defined in:
- lib/html2rss/config/selectors.rb
Overview
Holds the configurations of the selectors.
Defined Under Namespace
Classes: InvalidSelectorName, Selector
Constant Summary
collapse
- ITEMS_SELECTOR_NAME =
:items
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Selectors.
[View source]
19
20
21
22
|
# File 'lib/html2rss/config/selectors.rb', line 19
def initialize(config)
validate_config(config)
@config = config
end
|
Instance Method Details
permalink
#category_selector_names ⇒ Set<Symbol>
[View source]
48
49
50
|
# File 'lib/html2rss/config/selectors.rb', line 48
def category_selector_names
selector_keys_for(:categories)
end
|
permalink
#guid_selector_names ⇒ Set<Symbol>
[View source]
54
55
56
|
# File 'lib/html2rss/config/selectors.rb', line 54
def guid_selector_names
selector_keys_for(:guid, default: :title_or_description)
end
|
permalink
#item_selector_names ⇒ Set<Symbol>
[View source]
69
70
71
|
# File 'lib/html2rss/config/selectors.rb', line 69
def item_selector_names
@item_selector_names ||= config.keys.reject { |key| key == ITEMS_SELECTOR_NAME }.to_set
end
|
[View source]
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/html2rss/config/selectors.rb', line 34
def selector(name)
raise InvalidSelectorName, "invalid selector name: #{name}" unless selector?(name)
keywords = config[name].slice(*available_keys)
if (additional_keys = keywords.keys - available_keys).any?
Log.warn "additional keys (#{additional_keys.join(', ')}) present in selector #{name}"
end
Selector.new(keywords)
end
|
permalink
#selector?(name) ⇒ true, false
[View source]
27
28
29
|
# File 'lib/html2rss/config/selectors.rb', line 27
def selector?(name)
name != ITEMS_SELECTOR_NAME && item_selector_names.include?(name)
end
|
permalink
#selector_string(name) ⇒ String
Returns the CSS/XPath selector.
[View source]
63
64
65
|
# File 'lib/html2rss/config/selectors.rb', line 63
def selector_string(name)
Selector.new(config[name]).selector
end
|