Builder :: XmlMarkup使用

时间:2012-05-02 13:49:32

标签: ruby-on-rails ruby xml refactoring

我正在使用:: Builder :: XmlMarkup:

 # This is a class method in /lib, run ascynchronously using delayed_job. 
 # Bunch of file io / header stuff, then... 
 books.each do |book|
        xml.Product do
          xml.RecordReference "com.domain-#{book.id}"
          xml.NotificationType book.notification unless book.notification.blank?
          xml.ProductIdentifier do
            xml.ProductIDType "15"
            xml.IDValue book.isbn unless book.isbn.blank?
          end
          book.productcodes.each do |productcode|
            unless productcode.idtype == "15"
              xml.ProductIdentifier do
                xml.ProductIDType productcode.idtype unless productcode.idtype.blank?
                xml.IDValue productcode.idvalue unless productcode.idvalue.blank?
              end
            end
          end
          xml.ProductForm book.format unless book.format.blank?
          xml.ProductFormDetail book.format_detail unless book.format_detail.blank?
          xml.ProductFormDescription book.format_description unless book.format_description.blank?

等。麻烦的是,它继续另外250行。这是你打算如何构建充满各种元素的XML文件?它看起来并不像Rubyish。

0 个答案:

没有答案