class AcademicBenchmarks::Standards::Authority
Attributes
acronym[RW]
children[RW]
code[RW]
descr[RW]
description[RW]
guid[RW]
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/academic_benchmarks/standards/authority.rb, line 13 def self.from_hash(hash) self.new( acronym: hash["acronym"], guid: hash["guid"], descr: hash["descr"] ) end
new(acronym:, guid:, descr:, children: [])
click to toggle source
# File lib/academic_benchmarks/standards/authority.rb, line 21 def initialize(acronym:, guid:, descr:, children: []) @acronym = acronym @guid = guid @descr = descr @children = children end
Public Instance Methods
rebranch_children()
click to toggle source
Children are standards, so rebranch them so we have the following structure:
Authority -> Publication -> Document -> Section -> Standard
# File lib/academic_benchmarks/standards/authority.rb, line 32 def rebranch_children @seen = Set.new() @guid_to_obj = {} new_children = [] @children.each do |child| pub = reparent(child.document.publication, new_children) doc = reparent(child.document, pub.children) sec = reparent(child.section, doc.children) sec.children.push(child) end @children.replace(new_children) remove_instance_variable('@seen') remove_instance_variable('@guid_to_obj') end
Private Instance Methods
reparent(object, children)
click to toggle source
# File lib/academic_benchmarks/standards/authority.rb, line 49 def reparent(object, children) cached_object = (@guid_to_obj[object.guid] ||= object) children.push(cached_object) if @seen.add? cached_object.guid cached_object end