Skip to content

Instantly share code, notes, and snippets.

@hollingberry
Created October 24, 2015 00:44
Show Gist options
  • Save hollingberry/17939203ea088adfe482 to your computer and use it in GitHub Desktop.
Save hollingberry/17939203ea088adfe482 to your computer and use it in GitHub Desktop.
function capitalize(s) {
if (s == "id") {
return "ID"
} else {
return toupper(substr(s, 1, 1)) substr(s, 2, length(s) - 1)
}
}
function ruby2go(s) {
if (s == "String") { return "string" }
if (s == "Integer") { return "int" }
if (s == "Float") { return "float" }
if (s == "Boolean") { return "bool" }
return s
}
BEGIN {
print "package api\n"
}
/^ # / {
gsub(/`/, "")
$1=""; printf "//%s\n", $0
}
/^ class/ {
print "type", $2, "struct {"
}
/^ # @return/ {
match($0, /\[.*\]/)
return_type = substr($0, RSTART + 1, RLENGTH - 2)
sub(/\[.*\]/, "", $0)
$1=$2=""; docstring = substr($0, 3, length($0) - 1)
}
/^ # / {
$1=""; docstring += $0
}
/has_attribute/ {
sub(/:/, "", $2)
printf("\t\\\\ %s\n\t%s %s\n\n",
capitalize(docstring),
capitalize($2),
ruby2go(return_type))
}
/has_many/ {
}
END {
print "}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment