Class: Interscript::Node::Group
- Inherits:
-
Interscript::Node
- Object
- Interscript::Node
- Interscript::Node::Group
- Defined in:
- lib/interscript/node/group.rb,
lib/interscript/visualize/json.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Parallel, Sequential
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#reverse_run ⇒ Object
Returns the value of attribute reverse_run.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply_order(order) ⇒ Object
-
#initialize(reverse_run: nil) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #reorder_children(source, target) ⇒ Object
- #reverse ⇒ Object
- #to_hash ⇒ Object
- #to_visualization_array(map = self) ⇒ Object
Constructor Details
#initialize(reverse_run: nil) ⇒ Group
Returns a new instance of Group.
4 5 6 7 |
# File 'lib/interscript/node/group.rb', line 4 def initialize(reverse_run: nil) @reverse_run = reverse_run @children = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
2 3 4 |
# File 'lib/interscript/node/group.rb', line 2 def children @children end |
#reverse_run ⇒ Object
Returns the value of attribute reverse_run.
2 3 4 |
# File 'lib/interscript/node/group.rb', line 2 def reverse_run @reverse_run end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 |
# File 'lib/interscript/node/group.rb', line 35 def ==(other) super && self.children == other.children && self.reverse_run == other.reverse_run end |
#apply_order(order) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/interscript/node/group.rb', line 14 def apply_order(order) children_new = [nil] * @children.size order.each_with_index do |pos,idx| children_new[idx] = @children[pos] end @children = children_new #@children[source], @children[target] = @children[target], @children[source] self end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/interscript/node/group.rb', line 39 def inspect @children.map(&:inspect).join("\n").gsub(/^/, " ") end |
#reorder_children(source, target) ⇒ Object
9 10 11 12 |
# File 'lib/interscript/node/group.rb', line 9 def reorder_children(source,target) @children[source], @children[target] = @children[target], @children[source] self end |
#reverse ⇒ Object
24 25 26 27 28 |
# File 'lib/interscript/node/group.rb', line 24 def reverse self.class.new(reverse_run: reverse_run.nil? ? nil : !reverse_run).tap do |r| r.children = self.children.reverse.map(&:reverse) end end |
#to_hash ⇒ Object
30 31 32 33 |
# File 'lib/interscript/node/group.rb', line 30 def to_hash { :class => self.class.to_s, :children => @children.map{|x| x.to_hash} } end |
#to_visualization_array(map = self) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/interscript/visualize/json.rb', line 2 def to_visualization_array(map=self) out = [] self.children.each do |rule| case rule when Interscript::Node::Rule::Sub more = [] more << "before: #{rule.before.to_html(map)}" if rule.before more << "after: #{rule.after.to_html(map)}" if rule.after more << "<nobr>not before:</nobr> #{rule.not_before.to_html(map)}" if rule.not_before more << "<nobr>not after:</nobr> #{rule.not_after.to_html(map)}" if rule.not_after more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil? more = more.join(", ") out << { type: "Replace", from: rule.from.to_html(map), to: Symbol === rule.to ? rule.to : rule.to.to_html(map), more: more } when Interscript::Node::Group::Parallel out << { type: "Parallel", children: rule.to_visualization_array(map) } when Interscript::Node::Rule::Funcall more = rule.kwargs.map do |k,v| "#{k.to_s.gsub("_", " ")}: #{v}" end more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil? out << { type: rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase), more: more.join(", ") } when Interscript::Node::Rule::Run if rule.stage.map doc = map.dep_aliases[rule.stage.map].document stage = rule.stage.name else doc = map stage = rule.stage.name end more = [] more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil? out << { type: "Run", doc: doc.name, stage: stage, more: more.join(", "), } else out << { type: "Unknown", more: "<pre>#{h rule.inspect}</pre>" } end end out end |