Created
April 21, 2009 20:04
-
-
Save jmreidy/99351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "erb" | |
template = %q{ | |
package | |
{ | |
[Bindable] | |
[RemoteClass(alias="<%= package %>.<%= class_name%>")] | |
public class <%=class_name%> extends <%=parent_class%> | |
{ | |
<%publicVars.each do |publicVar| %> | |
private var _<%=publicVar[:name]%>:<%=publicVar[:type]%> | |
public function set <%=publicVar[:name]%>( value:<%=publicVar[:type]%> ):void | |
{ | |
_<%=publicVar[:name]%> = value; | |
} | |
public function get <%=publicVar[:name]%>():<%=publicVar[:type]%> | |
{ | |
return _<%=publicVar[:name]%>; | |
} | |
<%end%> | |
} | |
} | |
} | |
ARGV.each do |fileName| | |
f = File.open( fileName ) | |
src = f.read | |
f.close | |
b = binding | |
class_name = src.scan(/public class \w+/)[0].sub!(/public class /,'') | |
package = src.scan(/package \S+/)[0].sub(/package /,'').sub(/;/,'') | |
parent_class = src.scan(/extends \w+/) | |
parent_class[0].sub!(/extends /,'') if parent_class[0] != nil | |
publicVars = Array.new | |
src.scan(/set\w+\(\S+/) do |setter| | |
setterName = setter.sub(/set/,'').sub(/\(\S+/, '') | |
setterType = setter.scan(/\(\S+/)[0].sub(/\(/,'') | |
getter = src.scan("public #{setterType} get#{setterName}") | |
if getter[0] != nil | |
hash = {} | |
setterType = "ArrayCollection" if ( setterType.match(/</) ) #if there's a < that means we're dealing with a typed collection, or ArrayCollection in AS | |
setterType = "Number" if ( setterType.match(/Long/) ) #Java Longs convert to AS Numbers | |
hash[:name]=setterName[0].chr.downcase! + setterName[1,setterName.length] | |
hash[:type]=setterType | |
publicVars.push( hash ) | |
end | |
end | |
asClass = ERB.new(template, 0, "%<>"); | |
asFile = File.new( "#{class_name}VO.as", "w" ) | |
asFile.write( asClass.result(b) ) | |
asFile.close | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment