Module: Html2rss::RssBuilder

Defined in:
lib/html2rss/rss_builder.rb,
lib/html2rss/rss_builder/item.rb,
lib/html2rss/rss_builder/channel.rb,
lib/html2rss/rss_builder/stylesheet.rb

Overview

Builds the RSS 2.0 feed, which consists of the ‘<channel>’ and the ‘<item>’s tags in the RSS.

Defined Under Namespace

Classes: Channel, Item, Stylesheet

Constant Summary collapse

CHANNEL_TAGS =

Possible tags inside a RSS 2.0 <channel> tag.

%i[language author title description link ttl].freeze
ITEM_TAGS =

Possible tags inside a RSS 2.0 <item> tag.

%i[title link description author comments updated].freeze

Class Method Summary collapse

Class Method Details

.add_channel(maker, config) ⇒ Object

Adds channel information to the RSS maker.

Parameters:

  • maker (RSS::Maker)

    RSS maker instance.

  • config (Html2rss::Config)

    Configuration object containing feed details.



42
43
44
45
46
47
# File 'lib/html2rss/rss_builder.rb', line 42

def self.add_channel(maker, config)
  channel = maker.channel
  CHANNEL_TAGS.each do |tag|
    Channel.add(channel, config, [tag])
  end
end

.add_items(maker, config) ⇒ Object

Adds items to the RSS maker based on configuration.

Parameters:

  • maker (RSS::Maker)

    RSS maker instance.

  • config (Html2rss::Config)

    Configuration object containing feed details.



54
55
56
57
58
59
60
61
62
# File 'lib/html2rss/rss_builder.rb', line 54

def self.add_items(maker, config)
  item_attributes = extract_item_attributes(config)
  items = fetch_items(config)
  items.reverse! if config.items_order == :reverse

  items.each do |item|
    add_item(maker, item, item_attributes)
  end
end

.add_stylesheets(maker, stylesheets) ⇒ Object

Adds stylesheets to the RSS maker.

Parameters:

  • maker (RSS::Maker)

    RSS maker instance.

  • stylesheets (Array<String>)

    Array of stylesheets to add.



33
34
35
# File 'lib/html2rss/rss_builder.rb', line 33

def self.add_stylesheets(maker, stylesheets)
  Stylesheet.add(maker, stylesheets)
end

.build(config) ⇒ RSS::Rss

Builds an RSS 2.0 feed based on the provided configuration.

Parameters:

Returns:

  • (RSS::Rss)

    RSS feed object.



20
21
22
23
24
25
26
# File 'lib/html2rss/rss_builder.rb', line 20

def self.build(config)
  RSS::Maker.make('2.0') do |maker|
    add_stylesheets(maker, config.stylesheets)
    add_channel(maker, config)
    add_items(maker, config)
  end
end