Skip to content

Instantly share code, notes, and snippets.

@lemieuxster
Created July 18, 2012 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lemieuxster/3137373 to your computer and use it in GitHub Desktop.
Save lemieuxster/3137373 to your computer and use it in GitHub Desktop.
AS3 Annotation Parse in ruby
# Used to parse ActionScript style annotations
# [Annotation(key="value",foo="bar")]
# Where Annotation is the name and key and foo are attribute names.
# Quick string matching, does not create an "Annotation Object"
# for now, though that would be an improvement.
class AS3AnnotationParser
#Does the given annotation exist in the provided string?
def self.has_annotation (contents, name)
contents.match(/\[#{name}[^\]]?+\]/) != nil
end
#Get the annotation block
def self.get_annotation (contents, name)
contents.match(/\[#{name}[^\]]+\]/).to_s
end
#Parse out a value based on the given key
#Annotation block passed in as a string
def self.get_annotation_attribute (annotation, attr_name)
attributes = annotation.scan(/(\w+)\s?\=\s?\"([^\"]+)\"/)
attributes.each_with_index {|e, i|
if e[0] === attr_name
return e[1]
end
}
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment