From: umair iqbal Date: 2011-12-21T21:01:43+09:00 Subject: ruby Programming Help Hey Everyone I need your help regarding ruby programming. I have two classes. 1) Companies Class 2) Writer Class I want to generate a site-map XML file according to the companies names. In the Companies class I get the data about companies and I want to pass it to the writer class to write site-map Following are the classes... Anyone plz help me its very urgent ++++++++++++++Companies Class++++++++++++++ module Sitemap =begin Class Name: Companies Function: This class is responsible for getting the data and passing it to write. =end class Companies def initialize(country_version, directory, country_host) @country_version = country_version @directory = directory @country_host = country_host yield_data end #def slices #CountryVersion.each do |cv| #yield :country_version => cv #end #end def yield_data Company.find_each(:conditions => {:country_version_id => @country_version.id}) do |company| yield entry(company) end end private def entry(company) Entry.new( :url => ActionController::Integration::Session.new.url_for(:controller => 'companies', :action => 'show', :company_name => company.name, :host => @country_host.value), :filepath => @directory + "companies_sitemap.xml", :frequency => 0.8, :priority => 'monthly' ) end end end +++++++++++Writer++++++++++++ module Sitemap =begin Class Name: Writer Function: This class is responsible for creating the sitemap for each country version. =end class Writer include ActionController::UrlWriter def initialize(filepath) @filepath=filepath end def self.generate(filepath,&block) writer = new(filepath) writer.fill(&block) end def fill File.open(@filepath,"w") do |f| f.write(%[\n]) f.write(%[\n]) yield self f.write(%[]) f.close end zipped_file = 'gzip -f #{@filename}' return zipped_file end def write_entry(entry) xml.url do xml.loc entry.url xml.lastmod entry.lastmod xml.changefreq entry.frequency xml.priority entry.priority end end end end -- Posted via http://www.ruby-forum.com/.