Class: Pione::PNML::RuleDefinition
- Inherits:
-
PioneModel
- Object
- PioneModel
- Pione::PNML::RuleDefinition
- Defined in:
- lib/pione/pnml/pione-model.rb
Constant Summary collapse
- FLOW_RULE_TEMPLATE =
<<-RULE Rule <%= name %> <%- rule_conditions.each do |condition| -%> <%= condition %> <%- end -%> Flow <%- @flow_elements.each do |element| -%> <%= element.as_declaration(level: 1) %> <%- end -%> End RULE
- ACTION_RULE_TEMPLATE =
<<-RULE Rule <%= name %> <%- rule_conditions.each do |condition| -%> <%= condition %> <%- end -%> End RULE
- LITERATE_ACTION_RULE_TEMPLATE =
<<-RULE Rule <%= name %> <%- rule_conditions.each do |condition| -%> <%= condition %> <%- end -%> Action <%= Util::Indentation.indent(@action_content, 2) -%> End RULE
- WRAPPER_TEMPLATE =
<<-RULE Rule <%= name %> <%- rule_conditions.each do |condition| -%> <%= condition %> <%- end -%> Flow rule <%= @name %> End RULE
Instance Attribute Summary collapse
-
#action_content ⇒ Object
Returns the value of attribute action_content.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#features ⇒ Object
Returns the value of attribute features.
-
#flow_elements ⇒ Object
Returns the value of attribute flow_elements.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
-
#params ⇒ Object
Returns the value of attribute params.
-
#source_tickets ⇒ Object
Returns the value of attribute source_tickets.
-
#target_tickets ⇒ Object
Returns the value of attribute target_tickets.
-
#type ⇒ Object
Returns the value of attribute type.
-
#variable_bindings ⇒ Object
Returns the value of attribute variable_bindings.
Instance Method Summary collapse
- #action? ⇒ Boolean
-
#as_declaration(option = {}) ⇒ Object
Return the declaration form string.
- #external? ⇒ Boolean
- #flow? ⇒ Boolean
-
#generate_wrapper_name(name) ⇒ Object
Generate a name for wrapper rule.
-
#initialize(name, type, is_external, net_name, index, option = {}) ⇒ RuleDefinition
constructor
A new instance of RuleDefinition.
- #name ⇒ Object
-
#rule_conditions ⇒ Array<String>
Make rule conditions.
- #sort_data_list(data_list) ⇒ Object
- #template ⇒ Object
- #textize ⇒ Object
Methods inherited from PioneModel
Constructor Details
#initialize(name, type, is_external, net_name, index, option = {}) ⇒ RuleDefinition
Returns a new instance of RuleDefinition.
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/pione/pnml/pione-model.rb', line 750 def initialize(name, type, is_external, net_name, index, option={}) @name = name @type = type @is_external = is_external @net_name = net_name @index = index @inputs = option[:inputs] || [] @outputs = option[:outputs] || [] @params = option[:params] || [] @constraints = option[:constraints] || [] @features = option[:features] || [] @source_tickets = option[:source_tickets] || [] @target_tickets = option[:target_tickets] || [] @variable_bindings = option[:variable_bindings] || [] @conditions = option[:conditions] || [] @flow_elements = option[:flow_elements] || [] @action_content = nil end |
Instance Attribute Details
#action_content ⇒ Object
Returns the value of attribute action_content.
748 749 750 |
# File 'lib/pione/pnml/pione-model.rb', line 748 def action_content @action_content end |
#conditions ⇒ Object
Returns the value of attribute conditions.
745 746 747 |
# File 'lib/pione/pnml/pione-model.rb', line 745 def conditions @conditions end |
#constraints ⇒ Object
Returns the value of attribute constraints.
741 742 743 |
# File 'lib/pione/pnml/pione-model.rb', line 741 def constraints @constraints end |
#features ⇒ Object
Returns the value of attribute features.
742 743 744 |
# File 'lib/pione/pnml/pione-model.rb', line 742 def features @features end |
#flow_elements ⇒ Object
Returns the value of attribute flow_elements.
747 748 749 |
# File 'lib/pione/pnml/pione-model.rb', line 747 def flow_elements @flow_elements end |
#inputs ⇒ Object
Returns the value of attribute inputs.
738 739 740 |
# File 'lib/pione/pnml/pione-model.rb', line 738 def inputs @inputs end |
#outputs ⇒ Object
Returns the value of attribute outputs.
739 740 741 |
# File 'lib/pione/pnml/pione-model.rb', line 739 def outputs @outputs end |
#params ⇒ Object
Returns the value of attribute params.
740 741 742 |
# File 'lib/pione/pnml/pione-model.rb', line 740 def params @params end |
#source_tickets ⇒ Object
Returns the value of attribute source_tickets.
743 744 745 |
# File 'lib/pione/pnml/pione-model.rb', line 743 def source_tickets @source_tickets end |
#target_tickets ⇒ Object
Returns the value of attribute target_tickets.
744 745 746 |
# File 'lib/pione/pnml/pione-model.rb', line 744 def target_tickets @target_tickets end |
#type ⇒ Object
Returns the value of attribute type.
737 738 739 |
# File 'lib/pione/pnml/pione-model.rb', line 737 def type @type end |
#variable_bindings ⇒ Object
Returns the value of attribute variable_bindings.
746 747 748 |
# File 'lib/pione/pnml/pione-model.rb', line 746 def variable_bindings @variable_bindings end |
Instance Method Details
#action? ⇒ Boolean
773 774 775 |
# File 'lib/pione/pnml/pione-model.rb', line 773 def action? @type == :action end |
#as_declaration(option = {}) ⇒ Object
Return the declaration form string.
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/pione/pnml/pione-model.rb', line 786 def as_declaration(option={}) expr_source_tickets = if @source_tickets.size > 0 "(%s) ==> " % @source_tickets.map {|ticket| "%s" % ticket.name}.join(" | ") else "" end expr_target_tickets = if @target_tickets.size > 0 " ==> (%s)" % @target_tickets.map {|ticket| "%s" % ticket.name}.join(" | ") else "" end "rule %s%s%s" % [expr_source_tickets, name, expr_target_tickets] end |
#external? ⇒ Boolean
777 778 779 |
# File 'lib/pione/pnml/pione-model.rb', line 777 def external? @is_external end |
#flow? ⇒ Boolean
769 770 771 |
# File 'lib/pione/pnml/pione-model.rb', line 769 def flow? @type == :flow end |
#generate_wrapper_name(name) ⇒ Object
Generate a name for wrapper rule.
876 877 878 |
# File 'lib/pione/pnml/pione-model.rb', line 876 def generate_wrapper_name(name) "__%s_%s_%s__" % [@net_name, @name, @index] end |
#name ⇒ Object
781 782 783 |
# File 'lib/pione/pnml/pione-model.rb', line 781 def name external? ? generate_wrapper_name(@name) : @name end |
#rule_conditions ⇒ Array<String>
Make rule conditions.
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'lib/pione/pnml/pione-model.rb', line 806 def rule_conditions conditions = [] sort_data_list(@inputs).each do |input| conditions << input.as_declaration end sort_data_list(@outputs).each do |output| conditions << output.as_declaration end @params.each do |param| if param.kind_of?(Param) conditions += param.as_declarations else conditions << param end end @constraints.each do |constraint| if constraint.kind_of?(Constraint) conditions << constraint.as_declaration else conditions << constraint end end @features.each do |feature| if feature.kind_of?(Feature) conditions << feature.as_declaration else conditions << feature end end conditions end |
#sort_data_list(data_list) ⇒ Object
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/pione/pnml/pione-model.rb', line 838 def sort_data_list(data_list) data_list.sort do |a, b| priority_a = a.priority priority_b = b.priority if a.priority and b.priority a.priority <=> b.priority elsif a.priority 1 elsif b.priority -1 else 0 end end end |
#template ⇒ Object
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
# File 'lib/pione/pnml/pione-model.rb', line 859 def template if external? return Util::Indentation.cut(WRAPPER_TEMPLATE) end if flow? return Util::Indentation.cut(FLOW_RULE_TEMPLATE) end if @action_content return Util::Indentation.cut(LITERATE_ACTION_RULE_TEMPLATE) else return Util::Indentation.cut(ACTION_RULE_TEMPLATE) end end |
#textize ⇒ Object
855 856 857 |
# File 'lib/pione/pnml/pione-model.rb', line 855 def textize ERB.new(template, nil, "-").result(binding) end |