Guest User

Untitled

a guest
Apr 13th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. require 'rubygems'
  2. require 'active_record'
  3. require 'builder'
  4.  
  5. ActiveRecord::Base.establish_connection({
  6. :adapter => 'mysql',
  7. :database => 'gandc',
  8. :host => 'localhost',
  9. :username => 'noodl',
  10. :password => 'xxx'
  11. })
  12.  
  13. class Book < ActiveRecord::Base
  14. set_primary_key :entryID
  15. has_many :components, :foreign_key => 'entryID'
  16. end
  17.  
  18. class Component < ActiveRecord::Base
  19. set_primary_key :componentsID
  20. belongs_to :book, :foreign_key => 'entryID'
  21. end
  22.  
  23. buffer = ''
  24. xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
  25. xml.instruct!
  26.  
  27. Component.find(:all,
  28. :conditions => 'readyOmitDefer = 1',
  29. :limit => 10
  30. ).each do |comp|
  31.  
  32. next unless comp.book
  33.  
  34. xml.doc do
  35. [:entryID, :nameBinding, :ISBN, :ISBN10, :price].each do |attr|
  36. xml.field comp[attr], :name => attr
  37. end
  38.  
  39. [:title, :author, :section, :originalTitle, :director,
  40. :language, :publisher, :subtitle, :description].each do |attr|
  41. xml.field comp.book[attr], :name => attr
  42. end
  43. end
  44. end
  45.  
  46. puts buffer
Add Comment
Please, Sign In to add comment