Introducing the polyrex-schema gem
The polyrex-schema gem builds a Polyrex document from a string representation of the schema.
installation
gem install polyrex-schema
example
require 'polyrex-schema'
o = PolyrexSchema.new 'config/entry[name]/extension[string]/instruction[line,command]'
o.to_s
output:
<root> <config> <summary/> <records> <entry> <summary><name/></summary> <records> <extension> <summary><string/></summary> <records> <instruction> <summary><line/><command/></summary> <records/> </instruction> </records> </extension> </records> </entry> </records> </config> </root>
Polyrex-schema version 0.3
Polyrex-schema version 3.0 can now handle a schema that contain siblings recursively e.g.
require 'polyrex-schema'
o = PolyrexSchema.new 'a/{c[name,count];c2[age]/{f[title];f2[colour]}}/d[title]'
puts o.to_doc.xml pretty: true
output:
polyrex a/{c[name,count];c2[age]/{f[title];f2[colour]}}/d[title] c[name,count]/d[title] [!name] [!count] <title></title> d[title] [!title] c2[age]/{f[title];f2[colour]}/d[title] [!age] <title></title> f[title]/d[title] [!title] <title></title> d[title] [!title] f2[colour]/d[title] [!colour] <title></title> d[title] [!title]
Resources:
- jrobertson's polyrex-schema at master [github.com]