Module: MetaGen

Defined in:
lib/xspf.rb

Overview

:include: USAGE :main: USAGE

Class Method Summary collapse

Class Method Details

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

define the method



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/xspf.rb', line 23

def self.add_method(klass, meth_name, body, meth_rdoc)
  code = <<-CODE
  # #{meth_rdoc}
  def #{meth_name.downcase}
    @#{meth_name}
  end
  
  def #{meth_name.downcase}=(value)
    @#{meth_name.downcase} = value
  end

  private
  def parse_#{meth_name.downcase}
    begin
      #{body}
    rescue NoMethodError
      return nil
    end
  end
  CODE
  
  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, meth_rdoc) ⇒ Object

output in different formats FIXME Only works in parse mode, not in generation mode.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xspf.rb', line 57

def self.add_output_format(klass, format, meth_rdoc)
  xslt_path = "'#{File.join( File.dirname(__FILE__), %Q{xspf2#{format}.xsl} )}'"
  code = <<-CODE
    # #{meth_rdoc}
    def to_#{format}
      xslt = XML::XSLT.new
      xslt.xml = self.to_xml
      xslt.xsl = REXML::Document.new( File.new( #{xslt_path} ) )
      xslt.serve
    end
  CODE
  
  klass.module_eval(code)
 
  if $META_RDOC
    open($META_RDOC, 'a+') do |f|
      f.puts("class #{klass}\n #{code}\n end")
    end
  end

end