Class: AcademicBenchmarks::Standards::StandardsForest
- Inherits:
-
Object
- Object
- AcademicBenchmarks::Standards::StandardsForest
- Defined in:
- lib/academic_benchmarks/standards/standards_forest.rb
Instance Attribute Summary collapse
-
#orphans ⇒ Object
readonly
Returns the value of attribute orphans.
-
#trees ⇒ Object
readonly
Returns the value of attribute trees.
Instance Method Summary collapse
- #consolidate_under_root(root) ⇒ Object
- #empty? ⇒ Boolean
- #has_orphans? ⇒ Boolean
-
#initialize(data_hash) ⇒ StandardsForest
constructor
A new instance of StandardsForest.
- #single_tree? ⇒ Boolean
- #to_h ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data_hash) ⇒ StandardsForest
Returns a new instance of StandardsForest.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 6 def initialize(data_hash) @guid_to_standard = {} # a hash of guids to standards @trees = [] @orphans = [] process_items(data_hash) # upgrade the hash data to a StandardsTree object @trees.map! do |item| StandardsTree.new(item) end # We will still have the guid-to-standards saved at the Tree level, # so we can safely remove this variable and let the GC free the memory remove_instance_variable('@guid_to_standard') end |
Instance Attribute Details
#orphans ⇒ Object (readonly)
Returns the value of attribute orphans.
4 5 6 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 4 def orphans @orphans end |
#trees ⇒ Object (readonly)
Returns the value of attribute trees.
4 5 6 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 4 def trees @trees end |
Instance Method Details
#consolidate_under_root(root) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 22 def consolidate_under_root(root) trees.each do |tree| tree.root.parent = root tree.root.parent_guid = root.guid root.children.push(tree.root) end StandardsTree.new(root).tap{ |st| st.add_orphans(@orphans) } end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 35 def empty? @trees.empty? end |
#has_orphans? ⇒ Boolean
39 40 41 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 39 def has_orphans? @orphans.count > 0 end |
#single_tree? ⇒ Boolean
31 32 33 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 31 def single_tree? @trees.count == 1 end |
#to_h ⇒ Object
47 48 49 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 47 def to_h trees.map(&:to_h) end |
#to_json ⇒ Object
51 52 53 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 51 def to_json trees.map(&:to_h).to_json end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/academic_benchmarks/standards/standards_forest.rb', line 43 def to_s trees.map(&:to_s) end |