-
-
Save bogdanRada/6621960 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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