Class: Glaemscribe::API::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/api/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, rule_group) ⇒ Rule

Returns a new instance of Rule.



33
34
35
36
37
38
39
# File 'lib/api/rule.rb', line 33

def initialize(line, rule_group)
  @line       = line
  @rule_group = rule_group
  @mode       = @rule_group.mode
  @sub_rules  = []
  @errors     = []
end

Instance Attribute Details

#dst_sheaf_chainObject

Returns the value of attribute dst_sheaf_chain.



28
29
30
# File 'lib/api/rule.rb', line 28

def dst_sheaf_chain
  @dst_sheaf_chain
end

#errorsObject (readonly)

Returns the value of attribute errors.



31
32
33
# File 'lib/api/rule.rb', line 31

def errors
  @errors
end

#lineObject

Returns the value of attribute line.



27
28
29
# File 'lib/api/rule.rb', line 27

def line
  @line
end

#modeObject (readonly)

Returns the value of attribute mode.



30
31
32
# File 'lib/api/rule.rb', line 30

def mode
  @mode
end

#src_sheaf_chainObject

Returns the value of attribute src_sheaf_chain.



28
29
30
# File 'lib/api/rule.rb', line 28

def src_sheaf_chain
  @src_sheaf_chain
end

#sub_rulesObject (readonly)

Returns the value of attribute sub_rules.



29
30
31
# File 'lib/api/rule.rb', line 29

def sub_rules
  @sub_rules
end

Instance Method Details

#finalize(cross_schema) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
81
82
83
84
85
86
# File 'lib/api/rule.rb', line 41

def finalize(cross_schema)
  
  if(@errors.any?)
    @errors.each { |e|
      @mode.errors << Glaeml::Error.new(@line, e)
    }
    return         
  end
  
  srccounter  = SheafChainIterator.new(@src_sheaf_chain)
  dstcounter  = SheafChainIterator.new(@dst_sheaf_chain, cross_schema)
  
  if(srccounter.errors.any?)
    srccounter.errors.each{ |e| @mode.errors << Glaeml::Error.new(@line, e) }
    return
  end
  
  if(dstcounter.errors.any?)
    dstcounter.errors.each{ |e| @mode.errors << Glaeml::Error.new(@line, e) }
    return
  end     

  srcp = srccounter.prototype
  dstp = dstcounter.prototype
  
  if srcp != dstp
    @mode.errors << Glaeml::Error.new(@line, "Source and destination are not compatible (#{srcp} vs #{dstp})")
    return
  end
  
  begin 
   
    # All equivalent combinations ...
    src_combinations  = srccounter.combinations 
   
    # ... should be sent to one destination
    dst_combination   = dstcounter.combinations.first
 
    src_combinations.each{ |src_combination|
      @sub_rules << SubRule.new(self, src_combination, dst_combination)
    }

    dstcounter.iterate()
  end while srccounter.iterate()
  
end

#pObject



88
89
90
91
92
93
94
# File 'lib/api/rule.rb', line 88

def p
  ret = ("=" * 30) + "\n"
  @sub_rules.each{ |sr|
    ret += sr.p
  }
  ret
end