Class: XmlSchemaMapper::TestBuilder
- Inherits:
-
Object
- Object
- XmlSchemaMapper::TestBuilder
- Defined in:
- lib/xml_schema_mapper/test_builder.rb
Defined Under Namespace
Modules: Helper
Instance Method Summary collapse
- #build ⇒ Object
- #content_for(element) ⇒ Object
- #fill_array_element(element, instance) ⇒ Object
- #fill_element(element, instance) ⇒ Object
-
#initialize(klass) ⇒ TestBuilder
constructor
A new instance of TestBuilder.
Constructor Details
#initialize(klass) ⇒ TestBuilder
Returns a new instance of TestBuilder.
13 14 15 16 |
# File 'lib/xml_schema_mapper/test_builder.rb', line 13 def initialize(klass) @klass = klass @module = resolve_module end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/xml_schema_mapper/test_builder.rb', line 18 def build instance = @klass.new @klass.elements.each do |e| if e.array? fill_array_element(e, instance) else fill_element(e, instance) end end instance end |
#content_for(element) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xml_schema_mapper/test_builder.rb', line 51 def content_for(element) case element.type.kind when LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_SIMPLE element.type.base.name when LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC element.type.name else "content" end end |
#fill_array_element(element, instance) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xml_schema_mapper/test_builder.rb', line 38 def fill_array_element(element, instance) instance.send(element.writer, []) if element.simple? 3.times do instance.send(element.reader) << content_for(element) if instance.respond_to?(element.writer) end else 3.times do instance.send(element.reader) << resolve_element_builder(element).build if instance.respond_to?(element.writer) end end end |
#fill_element(element, instance) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/xml_schema_mapper/test_builder.rb', line 30 def fill_element(element, instance) if element.simple? instance.send(element.writer, content_for(element)) if instance.respond_to?(element.writer) else instance.send(element.writer, resolve_element_builder(element).build) if instance.respond_to?(element.writer) end end |