Class: Html2rss::AutoSource::RssBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/auto_source/rss_builder.rb

Overview

Converts the autosourced channel and articles to an RSS feed.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, articles:) ⇒ RssBuilder

Returns a new instance of RssBuilder.



27
28
29
30
# File 'lib/html2rss/auto_source/rss_builder.rb', line 27

def initialize(channel:, articles:)
  @channel = channel
  @articles = articles
end

Class Method Details

.add_guid(article, maker) ⇒ Object



10
11
12
13
14
15
# File 'lib/html2rss/auto_source/rss_builder.rb', line 10

def self.add_guid(article, maker)
  maker.guid.tap do |guid|
    guid.content = article.guid
    guid.isPermaLink = false
  end
end

.add_image(article, maker) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/html2rss/auto_source/rss_builder.rb', line 17

def self.add_image(article, maker)
  url = article.image || return

  maker.enclosure.tap do |enclosure|
    enclosure.url = url
    enclosure.type = Html2rss::Utils.guess_content_type_from_url(url)
    enclosure.length = 0
  end
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
39
# File 'lib/html2rss/auto_source/rss_builder.rb', line 32

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

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