#!/usr/bin/ruby txt = STDIN.read vars = txt.scan(/^\W*(private|public){0,1}\W*var\W*\_\_(\w*)\W*\:\W*(\w*)/) ascript = <<-EOF tell app "TextMate" activate choose from list { %s } with title "Variable auswaehlen" with prompt "Welche Variable als Basis benutzen?" end tell EOF displayList = [] varList = [] vars.each_with_index do |x,i| scope = x[0] name = x[1] type = x[2] urStr = "" if ( scope != nil ) urStr += "(" + scope.capitalize() + ") " end urStr += "__" + name if ( type != nil ) urStr += " : " + type end displayList.push( urStr ) varList.push( { "name" => name, "type" => type } ) end list = '"' + displayList.join( '", "' ) + '"' ascript = ascript % list params = "<< 'AS'\n #{ascript}\nAS" cmd = open("|osascript" + params) result = cmd.gets.chomp() cmd.close if ( result == "false" ) exit end index = displayList.index( result ) item = varList[ index ] getter = <<-EOF public function %s( Void ) : %s { return __%s; } EOF getter = getter % [ item[ "name" ], item[ "type" ], item[ "name" ] ] setter = <<-EOF public function set%s( val : %s ) : Void { __%s = val; } EOF setter = setter % [ item[ "name" ].sub(/./){$&.upcase}, item[ "type" ], item[ "name" ] ] snippet = getter + "\n" + setter print snippet