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)


17
18
19
20
21
22
# File 'lib/html2rss/config/channel.rb', line 17

def initialize(channel, params: {})
  raise ArgumentError, 'channel must be a hash' unless channel.is_a?(Hash)
  raise ArgumentError, 'missing key :url' unless channel[:url].is_a?(String)

  @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



83
84
85
86
87
# File 'lib/html2rss/config/channel.rb', line 83

def self.required_params_for_config(config)
  config.each_with_object(Set.new) do |(_, value), required_params|
    required_params.merge(value.scan(/%<([\w_\d]+)>/).flatten) if value.is_a?(String)
  end
end

Instance Method Details

#authorString

Returns:

  • (String)


34
35
36
# File 'lib/html2rss/config/channel.rb', line 34

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

#descriptionString

Returns:

  • (String)


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

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>)


28
29
30
# File 'lib/html2rss/config/channel.rb', line 28

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

#json?true, false

Returns:

  • (true, false)


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

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

#languageString

Returns language code.

Returns:

  • (String)

    language code



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

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

#time_zoneString

Returns time_zone name.

Returns:

  • (String)

    time_zone name



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

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

#titleString

Returns:

  • (String)


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

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

#ttlInteger

Returns:

  • (Integer)


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

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

#urlAddressable::URI

Returns:

  • (Addressable::URI)


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

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