Class: AcademicBenchmarks::Standards::StandardsTree
- Inherits:
-
Object
- Object
- AcademicBenchmarks::Standards::StandardsTree
- Defined in:
- lib/academic_benchmarks/standards/standards_tree.rb
Instance Attribute Summary collapse
-
#orphans ⇒ Object
readonly
Returns the value of attribute orphans.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #add_orphan(orphan) ⇒ Object
- #add_orphans(orphans) ⇒ Object
- #add_standard(standard) ⇒ Object
- #has_orphans? ⇒ Boolean
-
#initialize(root, build_item_hash: true, include_obsoletes: true) ⇒ StandardsTree
constructor
The item hash can optionally be built to permit the speedy addition of standards to the tree.
Constructor Details
#initialize(root, build_item_hash: true, include_obsoletes: true) ⇒ StandardsTree
The item hash can optionally be built to permit the speedy addition of standards to the tree. since the tree is unordered, adding to it can be expensive without this
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 13 def initialize(root, build_item_hash: true, include_obsoletes: true) @orphans = [] @root = root prune_obsolete_branches unless include_obsoletes if build_item_hash @item_hash = {} go_ahead_and_build_item_hash end end |
Instance Attribute Details
#orphans ⇒ Object (readonly)
Returns the value of attribute orphans.
6 7 8 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 6 def orphans @orphans end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 6 def root @root end |
Instance Method Details
#add_orphan(orphan) ⇒ Object
45 46 47 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 45 def add_orphan(orphan) add_orphans([orphan]) end |
#add_orphans(orphans) ⇒ Object
49 50 51 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 49 def add_orphans(orphans) @orphans.concat(orphans) end |
#add_standard(standard) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 24 def add_standard(standard) if standard.is_a?(Standard) parent = @item_hash ? @item_hash[standard.parent_guid] : find_parent(standard) unless parent raise StandardError.new( "Parent of standard not found in tree. Parent guid is " \ "'#{standard.parent_guid}' and child guid is '#{standard.guid}'" ) end parent.add_child(standard) standard.parent = parent elsif standard.is_a?(Hash) add_standard(Standard.new(standard)) else raise ArgumentError.new( "standard must be an 'AcademicBenchmarks::Standards::Standard' " \ "or a 'Hash' but was a #{standard.class}" ) end end |
#has_orphans? ⇒ Boolean
53 54 55 |
# File 'lib/academic_benchmarks/standards/standards_tree.rb', line 53 def has_orphans? @orphans.present? end |