Class: Fabulator::Core::Structurals::Group

Inherits:
Structural
  • Object
show all
Defined in:
lib/fabulator/core/structurals/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Structural

#accepts_structural?, accepts_structural?, contained_in, contains, element, #initialize, structurals

Constructor Details

This class inherits a constructor from Fabulator::Structural

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/fabulator/core/structurals/group.rb', line 5

def name
  @name
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/fabulator/core/structurals/group.rb', line 5

def params
  @params
end

#required_paramsObject

Returns the value of attribute required_params.



5
6
7
# File 'lib/fabulator/core/structurals/group.rb', line 5

def required_params
  @required_params
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/fabulator/core/structurals/group.rb', line 5

def tags
  @tags
end

Instance Method Details

#apply_constraints(context) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fabulator/core/structurals/group.rb', line 55

def apply_constraints(context)
  res = { :missing => [], :invalid => [], :valid => [], :messages => [] }
  passed = [ ]
  failed = [ ]
  @context.with(context) do |ctx|
    self.get_context(ctx).each do |root|
      @params.each do |param|
        @constraints.each do |c|
          r = c.test_constraint(ctx.with_root(root))
          passed += r[0]
          failed += r[1]
        end
        p_res = param.apply_constraints(ctx.with_root(root))
        res[:messages] += p_res[:messages]
        failed += p_res[:invalid]
        passed += p_res[:valid]
        res[:missing] += p_res[:missing]
      end
    end
  end
  res[:invalid] = failed.uniq
  res[:valid] = (passed - failed).uniq
  res[:messages].uniq!
  res[:missing] = (res[:missing] - passed).uniq
  res
end

#apply_filters(context) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fabulator/core/structurals/group.rb', line 38

def apply_filters(context)
  filtered = [ ]
 
  @context.with(context) do |ctx|

    self.get_context(ctx).each do |root|
      @params.each do |param|
        @filters.each do |f|
          filtered = filtered + f.apply_filter(ctx.with_root(root))
        end
        filtered = filtered + param.apply_filters(ctx.with_root(root))
      end
    end
  end
  filtered.uniq
end

#compile_xml(xml, context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fabulator/core/structurals/group.rb', line 18

def compile_xml(xml, context)
  super

  @required_params = [ ]

  @params.each do |p|
    @required_params += p.names if p.required?
  end

  @name = '' if @name.nil?
  @name.gsub!(/^\//, '')

  @groups.each do |g|
    @required_params += g.required_params.collect{ |n| (@name + '/' + n).gsub(/\/+/, '/') }
  end

  @params += @groups
  @groups = nil
end

#get_context(context) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/fabulator/core/structurals/group.rb', line 83

def get_context(context)
  return [ context.root ] if @select.nil?
  ret = [ ]
  context.in_context do |ctx|
    ret = @select.run(ctx)
  end
  ret
end