Class: Simrpc::Schema::Parser
- Inherits:
-
Object
- Object
- Simrpc::Schema::Parser
- Defined in:
- lib/simrpc/schema.rb
Overview
parse classes, methods, and data out of a xml definition
Class Method Summary collapse
-
.parse(args = {}) ⇒ Object
Parse and return a SchemaDef.
Class Method Details
.parse(args = {}) ⇒ Object
Parse and return a SchemaDef. Specify :schema argument containing xml schema to parse or :file containing location of file containing xml schema
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/simrpc/schema.rb', line 339 def self.parse(args = {}) if(!args[:schema].nil?) schema = args[:schema] elsif(!args[:file].nil?) schema = File.new(args[:file], "r") end schema_def = SchemaDef.new unless schema.nil? || schema == "" doc = REXML::Document.new(schema) # grab each method definition doc.elements.each('schema/method') do |ele| method = MethodDef.new method.name = ele.attributes["name"] Logger.debug "parsed schema method #{method.name}" ele.elements.each("param") do |param| param = _parse_data_def(param) method.parameters.push param Logger.debug " parameter #{param.name}" end ele.elements.each("return_value") do |rv| rv = _parse_data_def(rv) method.return_values.push rv Logger.debug " return_value #{rv.name}" end schema_def.methods.push method end # grab each class definition doc.elements.each('schema/class') do |ele| cl = ClassDef.new cl.name = ele.attributes["name"] cl.inherits = ele.attributes["inherits"] Logger.debug "parsed schema class #{cl.name}" ele.elements.each("member") do |mem| mem = _parse_data_def(mem) cl.members.push mem Logger.debug " member #{mem.name}" end schema_def.classes.push cl end end return schema_def end |