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, Stylesheet

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:



47
48
49
50
51
52
53
54
# File 'lib/html2rss/config.rb', line 47

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.



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

def channel
  @channel
end

Instance Method Details

#headersHash

Retrieves headers merged from global settings and channel headers.

Returns:

  • (Hash)

    Merged headers hash.



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

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.



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

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.



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

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