Class: PolyrexObjectMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrex-object-methods.rb

Overview

file: polyrex-object-methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ PolyrexObjectMethods

Returns a new instance of PolyrexObjectMethods.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/polyrex-object-methods.rb', line 7

def initialize(schema)
  
  a = schema.split('/')
  a.shift

  to_array = ->(x) do
    name, raw_fields = x.split('[')
    [name.capitalize, raw_fields ? raw_fields.chop.split(',')\
                                                        .map(&:strip) : []]
  end

  @a = a.inject([]) do |r,x|

    siblings = x[/[^\{]+(?=\})/]

    if siblings then
      siblings.split(/\s*;\s*/).inject(r) {|r2, s| r2 << to_array.call(s)}
    else
      r << to_array.call(x)
    end
  end

end

Instance Method Details

#to_aObject



31
32
33
# File 'lib/polyrex-object-methods.rb', line 31

def to_a
  @a
end