about summary refs log tree commit diff
path: root/app/lib/rss/item.rb
blob: c02991ace2bd1c326153a26a852698c9d904c72c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

class RSS::Item < RSS::Element
  def initialize
    super()

    @root = create_element('item')
  end

  def title(str)
    append_element('title', str)
  end

  def link(str)
    append_element('guid', str) do |guid|
      guid['isPermaLink'] = 'true'
    end

    append_element('link', str)
  end

  def pub_date(date)
    append_element('pubDate', date.to_formatted_s(:rfc822))
  end

  def description(str)
    append_element('description', str)
  end

  def category(str)
    append_element('category', str)
  end

  def enclosure(url, type, size)
    append_element('enclosure') do |enclosure|
      enclosure['url']    = url
      enclosure['length'] = size
      enclosure['type']   = type
    end
  end

  def media_content(url, type, size, &block)
    @root << RSS::MediaContent.with(url, type, size, &block)
  end
end