Class: Fabulator::Core::Structurals::Group
- Inherits:
-
Structural
- Object
- Action
- Structural
- Fabulator::Core::Structurals::Group
- Defined in:
- lib/fabulator/core/structurals/group.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#required_params ⇒ Object
Returns the value of attribute required_params.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #apply_constraints(context) ⇒ Object
- #apply_filters(context) ⇒ Object
- #compile_xml(xml, context) ⇒ Object
- #get_context(context) ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fabulator/core/structurals/group.rb', line 5 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/fabulator/core/structurals/group.rb', line 5 def params @params end |
#required_params ⇒ Object
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 |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/fabulator/core/structurals/group.rb', line 5 def @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 |