class AcademicBenchmarks::Standards::Standard
Attributes
children[R]
disciplines[RW]
document[RW]
education_levels[W]
guid[RW]
label[RW]
level[RW]
number[RW]
parent[RW]
parent_guid[RW]
section[RW]
seq[RW]
statement[RW]
status[R]
stem[RW]
utilizations[RW]
Public Class Methods
new(data)
click to toggle source
Before standards are rebranched in Authority#rebranch_children
or Document#rebranch_children, they have the following structure.
Standard
|-> Document
| |-> Publication
| |-> Authority
|-> Section
# File lib/academic_benchmarks/standards/standard.rb, line 30 def initialize(data) attributes = data["attributes"] @guid = attributes["guid"] @education_levels = attr_to_val_or_nil(EducationLevels, attributes, "education_levels") @label = attributes["label"] @level = attributes["level"] @section = attr_to_val_or_nil(Section, attributes, "section") @number = attr_to_val_or_nil(Number, attributes, "number") @status = attributes["status"] @disciplines = attr_to_val_or_nil(Disciplines, attributes, "disciplines") @children = [] @document = attr_to_val_or_nil(Document, attributes, "document") @statement = attr_to_val_or_nil(Statement, attributes, "statement") @utilizations = attr_to_vals(Utilizations, attributes["utilizations"]) @parent_guid = data.dig("relationships", "parent", "data", "id") end
Public Instance Methods
add_child(child)
click to toggle source
# File lib/academic_benchmarks/standards/standard.rb, line 49 def add_child(child) raise StandardError.new("Tried to add self as a child") if self == child unless child.is_a?(Standard) raise ArgumentError.new("Tried to set child that isn't a Standard") end child.parent = self @children.push(child) end
education_levels()
click to toggle source
# File lib/academic_benchmarks/standards/standard.rb, line 68 def education_levels return @education_levels if @education_levels # check to see if one of our parents has education levels. Use that if so p = parent while p return p.education_levels if p.education_levels p = p.parent end nil end
has_children?()
click to toggle source
# File lib/academic_benchmarks/standards/standard.rb, line 64 def has_children? @children.count > 0 end
remove_child(child)
click to toggle source
# File lib/academic_benchmarks/standards/standard.rb, line 59 def remove_child(child) child.parent = nil @children.delete(child) end
Private Instance Methods
attr_to_val_or_nil(klass, hash, attr)
click to toggle source
# File lib/academic_benchmarks/standards/standard.rb, line 82 def attr_to_val_or_nil(klass, hash, attr) return nil unless hash.key?(attr) klass.from_hash(hash[attr]) end