Class: Html2rss::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/html2rss/config.rb,
lib/html2rss/config/channel.rb,
lib/html2rss/config/selectors.rb

Overview

The Config class abstracts from the config data structure and provides default values.

Defined Under Namespace

Classes: Channel, ChannelMissing, ParamsMissing, Selectors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed_config, global = {}, params = {}) ⇒ Config

Initializes the Config object with feed configuration, global settings, and parameters.

Parameters:

  • feed_config (Hash<Symbol, Object>)

    The configuration hash containing ‘:channel` and `:selectors`.

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

    Global settings hash.

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

    Parameters hash.

Raises:



44
45
46
47
48
49
50
51
# File 'lib/html2rss/config.rb', line 44

def initialize(feed_config, global = {}, params = {})
  channel_config = feed_config[:channel]
  raise ChannelMissing, 'Channel configuration is missing in feed_config' unless channel_config

  @channel = Channel.new(channel_config, params:)
  @selectors = Selectors.new(feed_config[:selectors])
  @global = global
end

Instance Attribute Details

#channelObject (readonly)

Provides read-only access to the channel object.



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

def channel
  @channel
end

Instance Method Details

#headersHash

Retrieves headers merged from global settings and channel headers.

Returns:

  • (Hash)

    Merged headers hash.



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

def headers
  @global.fetch(:headers, {}).merge(@channel.headers)
end

#selector_attributes_with_channel(name) ⇒ Hash<Symbol, Object>

Retrieves selector attributes merged with channel attributes.

Parameters:

  • name (Symbol)

    Selector name.

Returns:

  • (Hash<Symbol, Object>)

    Merged attributes hash.



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

def selector_attributes_with_channel(name)
  @selectors.selector(name).to_h.merge(channel: @channel)
end

#stylesheetsArray<Stylesheet>

Retrieves stylesheets from global settings.

Returns:

  • (Array<Stylesheet>)

    Array of Stylesheet structs.



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

def stylesheets
  @global.fetch(:stylesheets, []).map { |attributes| Html2rss::RssBuilder::Stylesheet.new(**attributes) }
end