Class: AcademicBenchmarks::Standards::Authority

Inherits:
Object
  • Object
show all
Includes:
InstVarsToHash
Defined in:
lib/academic_benchmarks/standards/authority.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstVarsToHash

#to_h, #to_json, #to_s

Constructor Details

#initialize(acronym:, guid:, descr:, children: []) ⇒ Authority

Returns a new instance of Authority.



21
22
23
24
25
26
# File 'lib/academic_benchmarks/standards/authority.rb', line 21

def initialize(acronym:, guid:, descr:, children: [])
  @acronym = acronym
  @guid = guid
  @descr = descr
  @children = children
end

Instance Attribute Details

#acronymObject Also known as: code

Returns the value of attribute acronym.



8
9
10
# File 'lib/academic_benchmarks/standards/authority.rb', line 8

def acronym
  @acronym
end

#childrenObject

Returns the value of attribute children.



8
9
10
# File 'lib/academic_benchmarks/standards/authority.rb', line 8

def children
  @children
end

#descrObject Also known as: description

Returns the value of attribute descr.



8
9
10
# File 'lib/academic_benchmarks/standards/authority.rb', line 8

def descr
  @descr
end

#guidObject

Returns the value of attribute guid.



8
9
10
# File 'lib/academic_benchmarks/standards/authority.rb', line 8

def guid
  @guid
end

Class Method Details

.from_hash(hash) ⇒ Object



13
14
15
16
17
18
19
# 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

Instance Method Details

#rebranch_childrenObject

Children are standards, so rebranch them so we have the following structure:

Authority -> Publication -> Document -> Section -> Standard


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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