Class: TreeOrganizer
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#cyclical_links ⇒ Object
readonly
Returns the value of attribute cyclical_links.
Instance Method Summary collapse
- #add(issue, bread_crumbs = []) ⇒ Object
- #find_issue(issue_key) ⇒ Object
- #find_node(issue_key) ⇒ Object
- #flattened_issue_keys ⇒ Object
- #flattened_nodes ⇒ Object
-
#initialize(issues:) ⇒ TreeOrganizer
constructor
A new instance of TreeOrganizer.
- #walk_children(parent:, list:, depth:) ⇒ Object
Constructor Details
#initialize(issues:) ⇒ TreeOrganizer
Returns a new instance of TreeOrganizer.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jirametrics/tree_organizer.rb', line 32 def initialize issues: @issues = issues @root = Node.new @cyclical_links = [] @node_hash = {} @issues.each do |issue| add issue end end |
Instance Attribute Details
#cyclical_links ⇒ Object (readonly)
Returns the value of attribute cyclical_links.
4 5 6 |
# File 'lib/jirametrics/tree_organizer.rb', line 4 def cyclical_links @cyclical_links end |
Instance Method Details
#add(issue, bread_crumbs = []) ⇒ Object
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 |
# File 'lib/jirametrics/tree_organizer.rb', line 43 def add issue, bread_crumbs = [] parent_node = @root issue_node = find_node issue.key return issue_node if issue_node parent_issue = issue.parent if parent_issue cyclical = bread_crumbs.include? parent_issue.key bread_crumbs << issue.key if cyclical @cyclical_links << bread_crumbs.reverse else parent_node = find_node parent_issue.key end parent_node = add parent_issue, bread_crumbs if parent_node.nil? end issue_node = Node.new(issue: issue) if parent_node parent_node.children << issue_node @node_hash[issue_node.issue.key] = issue_node end issue_node end |
#find_issue(issue_key) ⇒ Object
74 75 76 |
# File 'lib/jirametrics/tree_organizer.rb', line 74 def find_issue issue_key @issues.find { |issue| issue.key == issue_key } end |
#find_node(issue_key) ⇒ Object
69 70 71 72 |
# File 'lib/jirametrics/tree_organizer.rb', line 69 def find_node issue_key @node_hash[issue_key] # @root.children.find { |node| node.issue.key == issue_key } end |
#flattened_issue_keys ⇒ Object
78 79 80 81 82 |
# File 'lib/jirametrics/tree_organizer.rb', line 78 def flattened_issue_keys flattened_nodes.collect do |node, depth| [node.issue.key, depth] end end |
#flattened_nodes ⇒ Object
84 85 86 87 88 |
# File 'lib/jirametrics/tree_organizer.rb', line 84 def flattened_nodes list = [] walk_children parent: @root, list: list, depth: 1 list end |
#walk_children(parent:, list:, depth:) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/jirametrics/tree_organizer.rb', line 90 def walk_children parent:, list:, depth: parent.children.sort.each do |node| list << [node, depth] walk_children parent: node, list: list, depth: depth + 1 end end |