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.

Parameters:

  • channel (Hash<Symbol, Object>)
  • params (Hash) (defaults to: {})

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>

Returns the required parameter names.

Parameters:

  • config (Hash<Symbol, Object>)

Returns:

  • (Set<String>)

    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

#authorString

Returns:

  • (String)


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

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

#descriptionString

Returns:

  • (String)


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.

Returns:

  • (Hash<Symbol, String>)


39
40
41
# File 'lib/html2rss/config/channel.rb', line 39

def headers
  config.fetch(:headers, {})
end

#json?true, false

Returns:

  • (true, false)


87
88
89
# File 'lib/html2rss/config/channel.rb', line 87

def json?
  config.fetch(:json, false)
end

#languageString

Returns language code.

Returns:

  • (String)

    language code



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

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

#time_zoneString

Returns time_zone name.

Returns:

  • (String)

    time_zone name



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

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

#titleString

Returns:

  • (String)


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

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

#ttlInteger

Returns:

  • (Integer)


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

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

#urlAddressable::URI

Returns:

  • (Addressable::URI)


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

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