Class: Html2rss::FeedBuilder::Rss

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_builder/rss.rb,
lib/html2rss/feed_builder/rss/stylesheet.rb

Overview

Builds an RSS Feed by providing channel, articles and stylesheets.

Defined Under Namespace

Classes: Stylesheet

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, articles:, generator:, stylesheets: []) ⇒ Rss

Returns a new instance of Rss.

Parameters:

  • channel (Html2rss::Channel)

    The channel information for the RSS feed.

  • articles (Array<Html2rss::Article>)

    The list of articles to include in the RSS feed.

  • stylesheets (Array<Hash>) (defaults to: [])

    An optional array of stylesheet configurations.

  • generator (String)

    required preformatted generator comment (from Status)

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
# File 'lib/html2rss/feed_builder/rss.rb', line 68

def initialize(channel:, articles:, generator:, stylesheets: [])
  raise ArgumentError, 'generator must be a non-blank String' if blank_string?(generator)

  @channel = channel
  @articles = articles
  @stylesheets = stylesheets
  @generator = generator
end

Class Method Details

.add_enclosure(enclosure, maker) ⇒ void

This method returns an undefined value.

Parameters:

  • enclosure (Html2rss::Article::Enclosure, nil)

    built enclosure object for the current RSS item

  • maker (RSS::Maker::RSS20::ItemsBase::ItemBase)

    RSS item builder



24
25
26
27
28
29
30
31
32
# File 'lib/html2rss/feed_builder/rss.rb', line 24

def add_enclosure(enclosure, maker)
  return unless enclosure

  maker.enclosure.tap do |enclosure_maker|
    enclosure_maker.url = enclosure.url.to_s
    enclosure_maker.type = enclosure.type
    enclosure_maker.length = enclosure.bytes_length
  end
end

.add_item(article, item_maker) ⇒ void

This method returns an undefined value.

Parameters:

  • article (Html2rss::Article)

    source article

  • item_maker (RSS::Maker::RSS20::ItemsBase::ItemBase)

    RSS item builder



14
15
16
17
18
19
# File 'lib/html2rss/feed_builder/rss.rb', line 14

def add_item(article, item_maker)
  add_item_string_values(article, item_maker)
  add_item_categories(article, item_maker)
  add_enclosure(ItemPresentation.rss_enclosure_for(article), item_maker)
  add_item_guid(article, item_maker)
end

Instance Method Details

#callRSS::Rss

Returns RSS 2.0 document instance.

Returns:

  • (RSS::Rss)

    RSS 2.0 document instance



78
79
80
81
82
83
84
85
# File 'lib/html2rss/feed_builder/rss.rb', line 78

def call
  RSS::Maker.make('2.0') do |maker|
    Stylesheet.add(maker, stylesheets)

    make_channel(maker.channel)
    make_items(maker)
  end
end