Class: PgVerify::Transform::PumlTransformation
- Inherits:
-
Object
- Object
- PgVerify::Transform::PumlTransformation
- Defined in:
- lib/pg-verify/transform/puml_transformation.rb
Instance Attribute Summary collapse
-
#render_actions ⇒ Object
Returns the value of attribute render_actions.
-
#render_guards ⇒ Object
Returns the value of attribute render_guards.
-
#render_labels ⇒ Object
Returns the value of attribute render_labels.
-
#render_precons ⇒ Object
Returns the value of attribute render_precons.
Instance Method Summary collapse
- #indented(str) ⇒ Object
-
#initialize(render_options = {}) ⇒ PumlTransformation
constructor
A new instance of PumlTransformation.
- #transform_component(graph, component, variable_state) ⇒ Object
- #transform_graph(graph, variable_state: nil, only: nil) ⇒ Object
- #transform_initial(graph, component) ⇒ Object
- #transform_range(range) ⇒ Object
- #transform_state(component, state) ⇒ Object
- #transform_transition(component, transition) ⇒ Object
- #transform_variable_state(graph, variable_state) ⇒ Object
- #transform_variables(component, variables, variable_state) ⇒ Object
Constructor Details
#initialize(render_options = {}) ⇒ PumlTransformation
Returns a new instance of PumlTransformation.
13 14 15 16 17 18 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 13 def initialize( = {}) @render_labels = [:render_labels].nil? ? true : [:render_labels] @render_precons = [:render_precons].nil? ? true : [:render_precons] @render_guards = [:render_guards].nil? ? true : [:render_guards] @render_actions = [:render_actions].nil? ? true : [:render_actions] end |
Instance Attribute Details
#render_actions ⇒ Object
Returns the value of attribute render_actions.
11 12 13 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 11 def render_actions @render_actions end |
#render_guards ⇒ Object
Returns the value of attribute render_guards.
10 11 12 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 10 def render_guards @render_guards end |
#render_labels ⇒ Object
Returns the value of attribute render_labels.
8 9 10 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 8 def render_labels @render_labels end |
#render_precons ⇒ Object
Returns the value of attribute render_precons.
9 10 11 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 9 def render_precons @render_precons end |
Instance Method Details
#indented(str) ⇒ Object
85 86 87 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 85 def indented(str) str.split("\n").map { |s| "\t#{s}" }.join("\n") end |
#transform_component(graph, component, variable_state) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 40 def transform_component(graph, component, variable_state) # Transform component states states_s = component.states.map { |s| transform_state(component, s) }.join("\n") # Transform component transitions trans_s = component.transitions.map { |t| transform_transition(component, t) }.join("\n") # Transform component variables vars = graph.variables.select_by_owner(component.name) vars_s = transform_variables(component, vars, variable_state) # Transform the initial state initial_s = transform_initial(graph, component) str = [ states_s, trans_s, vars_s, initial_s ].compact.join("\n") return "rectangle #{component.name} {\n#{indented(str)}\n}" end |
#transform_graph(graph, variable_state: nil, only: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 20 def transform_graph(graph, variable_state: nil, only: nil) components = graph.components components = components.select { |c| only.map(&:to_s).include?(c.name.to_s) } unless only.nil? parts = [] parts << components.map { |c| transform_component(graph, c, variable_state) }.join("\n\n") parts << transform_variable_state(graph, variable_state) unless variable_state.nil? parts = parts.compact.join("\n\n") return "@startuml Programmgraph\n#{parts}\n@enduml\n" end |
#transform_initial(graph, component) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 55 def transform_initial(graph, component) return "" # TODO: Find initial states # initial_state_name = "#{component.name}_initial" # str = "circle initial as #{initial_state_name} \n" # str += "#{initial_state_name} --> #{component.name}_#{component.initial_state}" # vars = graph.variables.select_by_owner(component.name) # init_var_s = vars.map(&:init_expression).compact.join(' && ') # str += ": #{init_var_s}" unless init_var_s.empty? # str += "\n" # return str end |
#transform_range(range) ⇒ Object
98 99 100 101 102 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 98 def transform_range(range) return range.to_s if range.is_a?(Range) return range.map(&:to_s).join(', ') if range.is_a?(Array) raise "Unknown type for range '#{range}::#{range.class}'" end |
#transform_state(component, state) ⇒ Object
69 70 71 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 69 def transform_state(component, state) return "rectangle #{state} as #{component.name}_#{state}" end |
#transform_transition(component, transition) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 73 def transform_transition(component, transition) precon = @render_precons ? transition.precon : nil guard = @render_guards ? transition.guard : nil action = @render_actions ? transition.action : nil label = [ precon, guard ].map(&:to_s).reject(&:empty?).join(" && ") label += " / " + action.to_s unless action.nil? label = ": #{label}" unless label.strip.empty? label = "" unless @render_labels return "#{component.name}_#{transition.src_state} --> #{component.name}_#{transition.tgt_state} #{label}" end |
#transform_variable_state(graph, variable_state) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 32 def transform_variable_state(graph, variable_state) state_variables = graph.state_variables() return state_variables.map { |var| state = variable_state[var.name] "rectangle #{state} as #{var.name}_#{state} #{Settings.puml.active_state_color}" }.join("\n") end |
#transform_variables(component, variables, variable_state) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/pg-verify/transform/puml_transformation.rb', line 89 def transform_variables(component, variables, variable_state) return nil if variables.empty? body = variables.map { |var| value = variable_state.nil? ? transform_range(var.range) : variable_state[var.name] "#{var.name} => #{value}" }.join("\n") return "map #{component.name}Variables {\n#{body}\n}" end |