Class: Contraption::RSSBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(posts) ⇒ RSSBuilder

Returns a new instance of RSSBuilder.



5
6
7
# File 'lib/contraption/rss_builder.rb', line 5

def initialize posts
  @posts = posts
end

Instance Method Details

#to_rssObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/contraption/rss_builder.rb', line 9

def to_rss
  RSS::Maker.make('2.0') do |maker|
    maker.channel.author = 'Casey Robinson'
    maker.channel.updated = Time.now.to_s
    maker.channel.link = 'http://rampantmonkey.com/rss'
    maker.channel.title = 'Rampant Monkey - Everything'
    maker.channel.description = 'Everything published on rampantmonkey.com'

    @posts.most_recent(-1).each do |post|
      maker.items.new_item do |item|
        item.link = "http://rampantmonkey.com/#{post.publication_date.strftime('%Y/%m')}/#{post.filename('.html')}"
        item.title = post.title
        item.pubDate = post.publication_date.to_s
        item.updated = post.publication_date.to_s
        item.description = post.summary
        item.content_encoded = post.body
      end
    end
  end
end