Class: RXSD::RubyDefinitionBuilder
- Inherits:
-
ClassBuilder
- Object
- ClassBuilder
- RXSD::RubyDefinitionBuilder
- Defined in:
- lib/rxsd/builders/ruby_definition.rb
Overview
Implements the RXSD::ClassBuilder interface to build string Ruby Class Definitions from xsd
Instance Attribute Summary
Attributes inherited from ClassBuilder
#associated_builder, #attribute_builders, #attribute_name, #base_builder, #klass, #klass_name
Instance Method Summary collapse
-
#build ⇒ Object
implementation of RXSD::ClassBuilder::build.
Methods inherited from ClassBuilder
#associated, #base=, #clone, #initialize
Constructor Details
This class inherits a constructor from RXSD::ClassBuilder
Instance Method Details
#build ⇒ Object
implementation of RXSD::ClassBuilder::build
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rxsd/builders/ruby_definition.rb', line 12 def build return "class #{@klass.to_s}\nend" if Parser.is_builtin? @klass # need the class name to build class return nil if @klass_name.nil? Logger.debug "building definition for #{@klass}/#{@klass_name} from xsd" # defined class w/ base superclass = "Object" unless @base_builder.nil? if ! @base_builder.klass_name.nil? superclass = @base_builder.klass_name elsif ! @base_builder.klass.nil? superclass = @base_builder.klass.to_s end end res = "class " + @klass_name + " < " + superclass + "\n" # define accessors for attributes @attribute_builders.each { |atb| unless atb.nil? att_name = nil if !atb.attribute_name.nil? att_name = atb.attribute_name.underscore elsif !atb.klass_name.nil? att_name = atb.klass_name.underscore else att_name = atb.klass.to_s.underscore end res += "attr_accessor :#{att_name}\n" end } res += "end" Logger.debug "definition #{res} built, returning" return res end |