Class: Rss2Html::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/rss2html/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Feed

Returns a new instance of Feed.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rss2html/feed.rb', line 26

def initialize(args)
  @title = args['title']
  @url = args['url']
  limit = args['limit']
  if limit
    @url += "&limit=#{limit}"
  end

  @feed_header = load_template('feed_header.html.erb')
  @feed_footer = load_template('feed_footer.html.erb')
  @item_template = load_template('item.html.erb')
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



24
25
26
# File 'lib/rss2html/feed.rb', line 24

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



24
25
26
# File 'lib/rss2html/feed.rb', line 24

def url
  @url
end

Instance Method Details

#fetchObject



39
40
41
42
43
44
45
46
47
# File 'lib/rss2html/feed.rb', line 39

def fetch
  open(@url) do |rss|
    feed = RSS::Parser.parse(rss)

    feed.entries.each do |item|
      yield item
    end
  end
end

#renderObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rss2html/feed.rb', line 49

def render
  feed = self
  output = @feed_header.result(binding)

  fetch do |entry|
    item = FeedItem.new(entry)
    output += @item_template.result(binding)
  end

  output += @feed_footer.result(binding)
end