Class: AcademicBenchmarks::Standards::Standard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InstVarsToHash

#to_h, #to_json, #to_s

Methods included from AttrToVals

#attr_to_vals

Constructor Details

#initialize(data) ⇒ Standard Also known as: from_hash

Before standards are rebranched in Authority#rebranch_children or Document#rebranch_children, they have the following structure.

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



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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/academic_benchmarks/standards/standard.rb', line 10

def children
  @children
end

#disciplinesObject

Returns the value of attribute disciplines.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def disciplines
  @disciplines
end

#documentObject

Returns the value of attribute document.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def document
  @document
end

#education_levelsObject



68
69
70
71
72
73
74
75
76
77
78
# 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

#guidObject

Returns the value of attribute guid.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def guid
  @guid
end

#labelObject

Returns the value of attribute label.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def label
  @label
end

#levelObject

Returns the value of attribute level.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def level
  @level
end

#numberObject

Returns the value of attribute number.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def number
  @number
end

#parentObject

Returns the value of attribute parent.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def parent
  @parent
end

#parent_guidObject

Returns the value of attribute parent_guid.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def parent_guid
  @parent_guid
end

#sectionObject

Returns the value of attribute section.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def section
  @section
end

#seqObject

Returns the value of attribute seq.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def seq
  @seq
end

#statementObject

Returns the value of attribute statement.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def statement
  @statement
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/academic_benchmarks/standards/standard.rb', line 10

def status
  @status
end

#stemObject

Returns the value of attribute stem.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def stem
  @stem
end

#utilizationsObject

Returns the value of attribute utilizations.



12
13
14
# File 'lib/academic_benchmarks/standards/standard.rb', line 12

def utilizations
  @utilizations
end

Instance Method Details

#add_child(child) ⇒ Object

Raises:

  • (StandardError)


49
50
51
52
53
54
55
56
57
# 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

#has_children?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/academic_benchmarks/standards/standard.rb', line 64

def has_children?
  @children.count > 0
end

#remove_child(child) ⇒ Object



59
60
61
62
# File 'lib/academic_benchmarks/standards/standard.rb', line 59

def remove_child(child)
  child.parent = nil
  @children.delete(child)
end