Class: Html2rss::FeedBuilder

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

Overview

The purpose is to build the feed, consisting of

  • the ‘channel’ and

  • the ‘item’

parts.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FeedBuilder

Returns a new instance of FeedBuilder.



13
14
15
# File 'lib/html2rss/feed_builder.rb', line 13

def initialize(config)
  @config = config
end

Class Method Details

.add_categories(categories, item_maker) ⇒ Object



27
28
29
# File 'lib/html2rss/feed_builder.rb', line 27

def self.add_categories(categories, item_maker)
  categories.each { |category| item_maker.categories.new_category.content = category }
end

.add_enclosure_from_url(url, item_maker) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/html2rss/feed_builder.rb', line 31

def self.add_enclosure_from_url(url, item_maker)
  return unless url

  enclosure = item_maker.enclosure
  content_type = MIME::Types.type_for(File.extname(url).delete('.'))

  enclosure.type = content_type.any? ? content_type.first.to_s : 'application/octet-stream'
  enclosure.length = 0
  enclosure.url = url
end

.add_guid(item, item_maker) ⇒ Object



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

def self.add_guid(item, item_maker)
  guid = item_maker.guid
  guid.content = Digest::SHA1.hexdigest(item.title)
  guid.isPermaLink = false
end

Instance Method Details

#rssRSS:Rss

Returns:

  • (RSS:Rss)


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

def rss
  RSS::Maker.make('2.0') do |maker|
    add_channel(maker.channel)

    items.each { |item| add_item(item, maker.items.new_item) }
  end
end