item.rb 852 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class RSS::Item < RSS::Element
  3. def initialize
  4. super()
  5. @root = create_element('item')
  6. end
  7. def title(str)
  8. append_element('title', str)
  9. end
  10. def link(str)
  11. append_element('guid', str) do |guid|
  12. guid['isPermaLink'] = 'true'
  13. end
  14. append_element('link', str)
  15. end
  16. def pub_date(date)
  17. append_element('pubDate', date.to_fs(:rfc822))
  18. end
  19. def description(str)
  20. append_element('description', str)
  21. end
  22. def category(str)
  23. append_element('category', str)
  24. end
  25. def enclosure(url, type, size)
  26. append_element('enclosure') do |enclosure|
  27. enclosure['url'] = url
  28. enclosure['length'] = size
  29. enclosure['type'] = type
  30. end
  31. end
  32. def media_content(url, type, size, &block)
  33. @root << RSS::MediaContent.with(url, type, size, &block)
  34. end
  35. end