Class: Html2rss::Config::Channel
- Inherits:
-
Object
- Object
- Html2rss::Config::Channel
- Defined in:
- lib/html2rss/config/channel.rb
Overview
Holds the configuration for the feed’s channel options. This contains:
-
the RSS channel attributes
-
html2rss options like json or custom HTTP-headers for the request
Class Method Summary collapse
-
.required_params_for_config(config) ⇒ Set<String>
The required parameter names.
Instance Method Summary collapse
- #author ⇒ String
- #description ⇒ String
-
#headers ⇒ Hash<Symbol, String>
The HTTP headers to use for the request.
-
#initialize(channel, params: {}) ⇒ Channel
constructor
A new instance of Channel.
- #json? ⇒ true, false
-
#language ⇒ String
Language code.
-
#time_zone ⇒ String
Time_zone name.
- #title ⇒ String
- #ttl ⇒ Integer
- #url ⇒ Addressable::URI
Constructor Details
#initialize(channel, params: {}) ⇒ Channel
Returns a new instance of Channel.
26 27 28 29 30 31 32 33 |
# File 'lib/html2rss/config/channel.rb', line 26 def initialize(channel, params: {}) raise ArgumentError, 'channel must be a hash' unless channel.is_a?(Hash) url = channel[:url] raise ArgumentError, 'missing key :url' unless url.is_a?(String) || url.is_a?(Addressable::URI) @config = process_params(channel, params.transform_keys(&:to_sym)) end |
Class Method Details
.required_params_for_config(config) ⇒ Set<String>
Returns the required parameter names.
17 18 19 20 21 |
# File 'lib/html2rss/config/channel.rb', line 17 def self.required_params_for_config(config) config.each_with_object(Set.new) do |(_, value), required_params| required_params.merge(value.scan(/%<(\w+)>[s|d]/).flatten) if value.is_a?(String) end end |
Instance Method Details
#author ⇒ String
45 46 47 |
# File 'lib/html2rss/config/channel.rb', line 45 def config.fetch(:author, 'html2rss') end |
#description ⇒ String
69 70 71 |
# File 'lib/html2rss/config/channel.rb', line 69 def description config.fetch(:description) { "Latest items from #{url}." } end |
#headers ⇒ Hash<Symbol, String>
The HTTP headers to use for the request.
39 40 41 |
# File 'lib/html2rss/config/channel.rb', line 39 def headers config.fetch(:headers, {}) end |
#json? ⇒ true, false
87 88 89 |
# File 'lib/html2rss/config/channel.rb', line 87 def json? config.fetch(:json, false) end |
#language ⇒ String
Returns language code.
63 64 65 |
# File 'lib/html2rss/config/channel.rb', line 63 def language config.fetch(:language, 'en') end |
#time_zone ⇒ String
Returns time_zone name.
81 82 83 |
# File 'lib/html2rss/config/channel.rb', line 81 def time_zone config.fetch(:time_zone, 'UTC') end |
#title ⇒ String
57 58 59 |
# File 'lib/html2rss/config/channel.rb', line 57 def title config.fetch(:title) { Utils.titleized_url(url) } end |
#ttl ⇒ Integer
51 52 53 |
# File 'lib/html2rss/config/channel.rb', line 51 def ttl config.fetch(:ttl, 360) end |
#url ⇒ Addressable::URI
75 76 77 |
# File 'lib/html2rss/config/channel.rb', line 75 def url Addressable::URI.parse(config[:url]).normalize end |