Module: OpenWFE::DefParser
- Defined in:
- lib/openwfe/expool/parser.rb
Overview
A process definition parser.
Currently supports XML, Ruby process pdefinitions, YAML and JSON.
Class Method Summary collapse
-
.parse(pdef) ⇒ Object
in : a process pdefinition out : a tree [ name, attributes, children ].
- .parse_string(pdef) ⇒ Object
-
.parse_xml(xml) ⇒ Object
The process definition is expressed as XML, turn that into an expression tree.
Class Method Details
.parse(pdef) ⇒ Object
in : a process pdefinition out : a tree [ name, attributes, children ]
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/openwfe/expool/parser.rb', line 57 def self.parse (pdef) return pdef \ if pdef.is_a?(Array) return parse_string(pdef) \ if pdef.is_a?(String) return pdef.do_make \ if pdef.is_a?(ProcessDefinition) or pdef.is_a?(Class) return pdef.to_a \ if pdef.is_a?(SimpleExpRepresentation) # for legacy stuff raise "cannot handle pdefinition of class #{pdef.class.name}" end |
.parse_string(pdef) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/openwfe/expool/parser.rb', line 75 def self.parse_string (pdef) pdef = pdef.strip #return SimpleExpRepresentation.from_xml(param) \ return parse_xml(pdef) \ if pdef[0, 1] == "<" return YAML.load(s) \ if pdef.match /^--- ./ # # else it's some ruby code to eval ProcessDefinition.eval_ruby_process_definition pdef, 2 end |
.parse_xml(xml) ⇒ Object
The process definition is expressed as XML, turn that into an expression tree.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/openwfe/expool/parser.rb', line 96 def self.parse_xml (xml) xml = REXML::Document.new(xml) \ if xml.is_a?(String) xml = xml.root \ if xml.is_a?(REXML::Document) if xml.is_a?(REXML::Text) s = xml.to_s.strip return s if s.length > 0 return nil end return nil if xml.is_a?(REXML::Comment) # xml element thus... name = xml.name attributes = xml.attributes.inject({}) do |r, (k, v)| r[k] = v r end rep = [ name, attributes, [] ] xml.children.each do |c| #r = if c.is_a?(REXML::Element) and c.prefix != xml.prefix # c #else # parse_xml c #end r = parse_xml c rep.last << r if r end rep end |