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
# File 'lib/html2rss/config/channel.rb', line 26

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



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_\d]+)>/).flatten) if value.is_a?(String)
  end
end

Instance Method Details

#authorString

Returns:

  • (String)


43
44
45
# File 'lib/html2rss/config/channel.rb', line 43

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

#descriptionString

Returns:

  • (String)


67
68
69
# File 'lib/html2rss/config/channel.rb', line 67

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


37
38
39
# File 'lib/html2rss/config/channel.rb', line 37

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

#json?true, false

Returns:

  • (true, false)


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

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

#languageString

Returns language code.

Returns:

  • (String)

    language code



61
62
63
# File 'lib/html2rss/config/channel.rb', line 61

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

#time_zoneString

Returns time_zone name.

Returns:

  • (String)

    time_zone name



79
80
81
# File 'lib/html2rss/config/channel.rb', line 79

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

#titleString

Returns:

  • (String)


55
56
57
# File 'lib/html2rss/config/channel.rb', line 55

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

#ttlInteger

Returns:

  • (Integer)


49
50
51
# File 'lib/html2rss/config/channel.rb', line 49

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

#urlAddressable::URI

Returns:

  • (Addressable::URI)


73
74
75
# File 'lib/html2rss/config/channel.rb', line 73

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