element.rb 489 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class RSS::Element
  3. def self.with(*, &block)
  4. new(*).tap(&block).to_element
  5. end
  6. def create_element(name, content = nil)
  7. Ox::Element.new(name).tap do |element|
  8. yield element if block_given?
  9. element << content if content.present?
  10. end
  11. end
  12. def append_element(name, content = nil)
  13. @root << create_element(name, content).tap do |element|
  14. yield element if block_given?
  15. end
  16. end
  17. def to_element
  18. @root
  19. end
  20. end