Class: Html2rss::Config::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/config/channel.rb

Overview

Holds the configuration for the feed’s channel options. This contains:

  1. the RSS channel attributes

  2. html2rss options like json or custom HTTP-headers for the request

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, params: {}) ⇒ Channel

Returns a new instance of Channel.

Raises:

  • (ArgumentError)


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>



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

#authorString



45
46
47
# File 'lib/html2rss/config/channel.rb', line 45

def author
  config.fetch(:author, 'html2rss')
end

#descriptionString



69
70
71
# File 'lib/html2rss/config/channel.rb', line 69

def description
  config.fetch(:description) { "Latest items from #{url}." }
end

#headersHash<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

#languageString



63
64
65
# File 'lib/html2rss/config/channel.rb', line 63

def language
  config.fetch(:language, 'en')
end

#strategySymbol



93
94
95
# File 'lib/html2rss/config/channel.rb', line 93

def strategy
  config.fetch(:strategy) { RequestService.default_strategy_name }.to_sym
end

#time_zoneString



81
82
83
# File 'lib/html2rss/config/channel.rb', line 81

def time_zone
  config.fetch(:time_zone, 'UTC')
end

#titleString



57
58
59
# File 'lib/html2rss/config/channel.rb', line 57

def title
  config.fetch(:title) { Utils.titleized_channel_url(url) }
end

#ttlInteger



51
52
53
# File 'lib/html2rss/config/channel.rb', line 51

def ttl
  config.fetch(:ttl, 360)
end

#urlAddressable::URI



75
76
77
# File 'lib/html2rss/config/channel.rb', line 75

def url
  Addressable::URI.parse(config[:url]).normalize
end