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:, 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.



64
65
66
67
68
# File 'lib/html2rss/feed_builder/rss.rb', line 64

def initialize(channel:, articles:, stylesheets: [])
  @channel = channel
  @articles = articles
  @stylesheets = stylesheets
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(article.enclosure, 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



71
72
73
74
75
76
77
78
# File 'lib/html2rss/feed_builder/rss.rb', line 71

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

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