Introducing the Polyrex gem

require 'polyrex' 

polyrex = Polyrex.new 'entities/section[name]/entity[name,count]' 
polyrex.create.section(name: 'main') do |create|  
  create.entity name: 'entry', count: 1 
end

polyrex.create.section(name: 'tags') do |create|
  create.entity name: 'ruby', count: 1 
  create.entity name: 'rexml', count: 1 
  create.entity name: 'array', count: 1 
end
puts polyrex.to_xml pretty: true

(polyrex.public_methods - Object.public_methods).sort
#=> [:create, :create_entity, :create_section, :delete, :element, :entity, :find_by_entity_count, :find_by_entity_name, :find_by_id, :find_by_section_name, :format_masks, :id, :id_counter, :id_counter=, :parse, :record, :records, :save, :schema, :schema=, :section, :summary, :summary_fields, :summary_fields=, :to_a, :to_xml, :to_xslt, :xpath, :xslt_schema, :xslt_schema=]

output:

puts

polyrex.to_xml pretty: true

<?xml version='1.0' encoding='UTF-8'?>
<entities>
  <summary>
    <recordx_type>polyrex</recordx_type>
    <schema>entities/section[name]/entity[name,count]</schema>
  </summary>
  <records>
    <section id='1'>
      <summary>
        <name>main</name>
        <format_mask>[!name]</format_mask>
        <recordx_type>polyrex</recordx_type>
        <schema>section[name]</schema>
      </summary>
      <records>
        <entity id='2'>
          <summary>
            <name>entry</name>
            <count>1</count>
            <format_mask>[!name] [!count]</format_mask>
            <recordx_type>polyrex</recordx_type>
            <schema>entity[name,count]</schema>
          </summary>
          <records></records>
        </entity>
      </records>
    </section>
    <section id='3'>
      <summary>
        <name>tags</name>
        <format_mask>[!name]</format_mask>
        <recordx_type>polyrex</recordx_type>
        <schema>section[name]</schema>
      </summary>
      <records>
        <entity id='4'>
          <summary>
            <name>ruby</name>
            <count>1</count>
            <format_mask>[!name] [!count]</format_mask>
            <recordx_type>polyrex</recordx_type>
            <schema>entity[name,count]</schema>
          </summary>
          <records></records>
        </entity>
        <entity id='5'>
          <summary>
            <name>rexml</name>
            <count>1</count>
            <format_mask>[!name] [!count]</format_mask>
            <recordx_type>polyrex</recordx_type>
            <schema>entity[name,count]</schema>
          </summary>
          <records></records>
        </entity>
        <entity id='6'>
          <summary>
            <name>array</name>
            <count>1</count>
            <format_mask>[!name] [!count]</format_mask>
            <recordx_type>polyrex</recordx_type>
            <schema>entity[name,count]</schema>
          </summary>
          <records></records>
        </entity>
      </records>
    </section>
  </records>
</entities>

Tags:
Source:
2107hrs.txt
Published:
14-03-2012 21:07