Module: MetaGen

Defined in:
lib/xspf.rb

Overview

:main: XSPF

Class Method Summary collapse

Class Method Details

.add_method(klass, meth_name, body, meth_rdoc) ⇒ Object

define the method



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xspf.rb', line 22

def self.add_method(klass, meth_name, body, meth_rdoc)
  code = "# #{meth_rdoc}\n def #{meth_name.downcase}; begin; #{body}; rescue NoMethodError; return nil; end; end"

  klass.module_eval(code)
 
  # hook to write klass + name attrib to a file
  if $META_RDOC
    open($META_RDOC, 'a+') do |f|
      f.puts("class #{klass}\n #{code}\n end")
    end
  end
  
end

.add_output_format(klass, format, xspf, meth_rdoc) ⇒ Object

output in different formats



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/xspf.rb', line 37

def self.add_output_format(klass, format, xspf, meth_rdoc)
  xslt_path = "'#{File.join( File.dirname(__FILE__), %Q{xspf2#{format}.xsl} )}'"
  code = "# #{meth_rdoc}\n def to_#{format}; xslt = XML::XSLT.new; xslt.xml = xspf; xslt.xsl = REXML::Document.new( File.new( #{xslt_path} ) ); xslt.serve; end"

  klass.module_eval(code)
 
  if $META_RDOC
    open($META_RDOC, 'a+') do |f|
      f.puts("class #{klass}\n #{code}\n end")
    end
  end

end