Class: Html2rss::Config
- Inherits:
-
Object
- Object
- Html2rss::Config
- Defined in:
- lib/html2rss/config.rb
Overview
The Config class abstracts from the config data structure and provides default values.
Instance Method Summary collapse
- #attribute?(name) ⇒ Boolean
- #attribute_names ⇒ Object
- #attribute_options(name) ⇒ Object
- #author ⇒ Object
- #category_selectors ⇒ Object
- #description ⇒ Object
- #generated_title ⇒ Object
- #headers ⇒ Object
-
#initialize(feed_config, global_config = {}) ⇒ Config
constructor
A new instance of Config.
- #items_order ⇒ Object
- #json? ⇒ Boolean
- #language ⇒ Object
- #selector(name) ⇒ Object
- #time_zone ⇒ Object
- #title ⇒ Object
- #ttl ⇒ Object
- #url ⇒ Object (also: #link)
Constructor Details
#initialize(feed_config, global_config = {}) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 |
# File 'lib/html2rss/config.rb', line 8 def initialize(feed_config, global_config = {}) @global_config = global_config.deep_symbolize_keys @feed_config = feed_config.deep_symbolize_keys @channel_config = @feed_config.fetch(:channel, {}) end |
Instance Method Details
#attribute?(name) ⇒ Boolean
64 65 66 |
# File 'lib/html2rss/config.rb', line 64 def attribute?(name) attribute_names.include?(name) end |
#attribute_names ⇒ Object
83 84 85 |
# File 'lib/html2rss/config.rb', line 83 def attribute_names @attribute_names ||= feed_config.fetch(:selectors, {}).keys.tap { |attrs| attrs.delete(:items) } end |
#attribute_options(name) ⇒ Object
60 61 62 |
# File 'lib/html2rss/config.rb', line 60 def (name) feed_config.dig(:selectors).fetch(name, {}).merge(channel: channel_config) end |
#author ⇒ Object
14 15 16 |
# File 'lib/html2rss/config.rb', line 14 def channel_config.fetch :author, 'html2rss' end |
#category_selectors ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/html2rss/config.rb', line 68 def category_selectors categories = feed_config.dig(:selectors, :categories) return [] unless categories categories = categories.keep_if { |category| category.to_s != '' } categories.map!(&:to_sym) categories.uniq! categories end |
#description ⇒ Object
39 40 41 |
# File 'lib/html2rss/config.rb', line 39 def description channel_config.fetch :description, "Latest items from #{url}." end |
#generated_title ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/html2rss/config.rb', line 26 def generated_title uri = URI(url) nicer_path = uri.path.split('/') nicer_path.reject! { |part| part == '' } nicer_path.any? ? "#{uri.host}: #{nicer_path.join(' ').titleize}" : uri.host end |
#headers ⇒ Object
56 57 58 |
# File 'lib/html2rss/config.rb', line 56 def headers global_config.fetch(:headers, {}).merge(channel_config.fetch(:headers, {})) end |
#items_order ⇒ Object
87 88 89 |
# File 'lib/html2rss/config.rb', line 87 def items_order feed_config.dig(:selectors, :items, :order)&.to_sym end |
#json? ⇒ Boolean
52 53 54 |
# File 'lib/html2rss/config.rb', line 52 def json? channel_config.fetch :json, false end |
#language ⇒ Object
35 36 37 |
# File 'lib/html2rss/config.rb', line 35 def language channel_config.fetch :language, 'en' end |
#selector(name) ⇒ Object
79 80 81 |
# File 'lib/html2rss/config.rb', line 79 def selector(name) feed_config.dig(:selectors, name, :selector) end |
#time_zone ⇒ Object
48 49 50 |
# File 'lib/html2rss/config.rb', line 48 def time_zone channel_config.fetch :time_zone, 'UTC' end |
#title ⇒ Object
22 23 24 |
# File 'lib/html2rss/config.rb', line 22 def title channel_config.fetch(:title) { generated_title } end |
#ttl ⇒ Object
18 19 20 |
# File 'lib/html2rss/config.rb', line 18 def ttl channel_config.fetch :ttl, 360 end |
#url ⇒ Object Also known as: link
43 44 45 |
# File 'lib/html2rss/config.rb', line 43 def url channel_config.dig :url end |