class Html2rss::FeedBuilder
The purpose is to build the feed, consisting of
-
the 'channel' and
-
the 'item'
parts.
Attributes
config[R]
Public Class Methods
add_categories(categories, item_maker)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
new(config)
click to toggle source
# File lib/html2rss/feed_builder.rb, line 13 def initialize(config) @config = config end
Public Instance Methods
rss()
click to toggle source
@return [RSS:Rss]
# 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
Private Instance Methods
add_channel(channel_maker)
click to toggle source
# File lib/html2rss/feed_builder.rb, line 52 def add_channel(channel_maker) %i[language author title description link ttl].each do |attribute_name| channel_maker.public_send("#{attribute_name}=", config.public_send(attribute_name)) end channel_maker.generator = "html2rss V. #{::Html2rss::VERSION}" channel_maker.lastBuildDate = Time.now end
add_item(item, item_maker)
click to toggle source
# File lib/html2rss/feed_builder.rb, line 71 def add_item(item, item_maker) item.available_attributes.each do |attribute_name| item_maker.public_send("#{attribute_name}=", item.public_send(attribute_name)) end self.class.add_categories(item.categories, item_maker) self.class.add_enclosure_from_url(item.enclosure_url, item_maker) if item.enclosure? self.class.add_guid(item, item_maker) end
items()
click to toggle source
# File lib/html2rss/feed_builder.rb, line 61 def items return @items if defined?(@items) items = Item.from_url(config.url, config) items.reverse! if config.items_order == :reverse @items = items end