Class: PolyrexSchema
- Inherits:
-
Object
- Object
- PolyrexSchema
- Defined in:
- lib/polyrex-schema.rb
Instance Attribute Summary collapse
-
#to_a ⇒ Object
readonly
Returns the value of attribute to_a.
-
#to_doc ⇒ Object
readonly
Returns the value of attribute to_doc.
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
-
#to_s ⇒ Object
readonly
Returns the value of attribute to_s.
-
#to_schema ⇒ Object
readonly
Returns the value of attribute to_schema.
Instance Method Summary collapse
-
#initialize(s = nil) ⇒ PolyrexSchema
constructor
A new instance of PolyrexSchema.
- #parse(s) ⇒ Object
Constructor Details
#initialize(s = nil) ⇒ PolyrexSchema
Returns a new instance of PolyrexSchema.
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 |
# File 'lib/polyrex-schema.rb', line 12 def initialize(s=nil) if s then if s =~ /\// then s.prepend 'root/' if s[0] == '{' r = add_node split(s) r[3] << node('recordx_type', 'polyrex') @doc = Rexle.new(r) @to_a = scan_to_a(@doc.root.xpath 'records/*') @to_h = scan_to_h(@doc.root.xpath 'records/*') @to_doc = @doc @to_s = @doc.to_s else a = [s[/^[^\[]+/], *s[/(?<=\[)[^\]]+/].split(/ *, */)].map(&:to_sym) @to_a = [a] h2 = { format_mask: a[1..-1].map {|x| "[!%s]" % x }.join(' '), schema: "%s[%s]" % [a[0], a[1..-1].join(', ')], recordx_type: 'polyrex' } h = {a[0] => {summary: a[1..-1]\ .zip(Array.new(a.length-1)).to_h.merge(h2), records: nil }} @to_doc = Rexle.new(RexleBuilder.new(h, debug: false).to_a) end end end |
Instance Attribute Details
#to_a ⇒ Object (readonly)
Returns the value of attribute to_a.
10 11 12 |
# File 'lib/polyrex-schema.rb', line 10 def to_a @to_a end |
#to_doc ⇒ Object (readonly)
Returns the value of attribute to_doc.
10 11 12 |
# File 'lib/polyrex-schema.rb', line 10 def to_doc @to_doc end |
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
10 11 12 |
# File 'lib/polyrex-schema.rb', line 10 def to_h @to_h end |
#to_s ⇒ Object (readonly)
Returns the value of attribute to_s.
10 11 12 |
# File 'lib/polyrex-schema.rb', line 10 def to_s @to_s end |
#to_schema ⇒ Object (readonly)
Returns the value of attribute to_schema.
10 11 12 |
# File 'lib/polyrex-schema.rb', line 10 def to_schema @to_schema end |
Instance Method Details
#parse(s) ⇒ Object
49 50 51 52 53 |
# File 'lib/polyrex-schema.rb', line 49 def parse(s) doc = Rexle.new s @to_schema = scan_to_schema doc.root self end |