Class: AcademicBenchmarks::Standards::Standard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RemoveObsoleteChildren

#remove_obsolete_children

Methods included from InstVarsToHash

#to_h, #to_json, #to_s

Constructor Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/academic_benchmarks/standards/standard.rb', line 19

def initialize(data)
  data = data["data"] if data["data"]
  @guid = data["guid"]
  @grade = attr_to_val_or_nil(Grade, data, "grade")
  @label = data["label"]
  @level = data["level"]
  @course = attr_to_val_or_nil(Course, data, "course")
  @number = data["number"]
  @status = data["status"]
  @parent = nil
  @subject = attr_to_val_or_nil(Subject, data, "subject")
  @deepest = data["deepest"]
  @version = data["version"]
  @children = []
  @document = attr_to_val_or_nil(Document, data, "document")
  @authority = attr_to_val_or_nil(Authority, data, "authority")
  @adopt_year = data["adopt_year"]
  @description = data["descr"]
  @subject_doc = attr_to_val_or_nil(SubjectDoc, data, "subject_doc")
  @has_relations = attr_to_val_or_nil(HasRelations, data, "has_relations")

  # Parent guid extraction can be a little more complicated
  if data["parent"] && data["parent"].is_a?(String)
    @parent_guid = data["parent"]
  elsif data["parent"] && data["parent"].is_a?(Hash)
    @parent_guid = data["parent"]["guid"]
  end
end

Instance Attribute Details

#adopt_yearObject

Returns the value of attribute adopt_year.



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

def adopt_year
  @adopt_year
end

#authorityObject

Returns the value of attribute authority.



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

def authority
  @authority
end

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#courseObject

Returns the value of attribute course.



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

def course
  @course
end

#deepestObject

Returns the value of attribute deepest.



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

def deepest
  @deepest
end

#descriptionObject Also known as: descr

Returns the value of attribute description.



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

def description
  @description
end

#documentObject

Returns the value of attribute document.



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

def document
  @document
end

#gradeObject



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/academic_benchmarks/standards/standard.rb', line 101

def grade
  return @grade if @grade

  # check to see if one of our parents has a grade.  Use that if so
  p = parent
  while p
    return p.grade if p.grade
    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

#has_relationsObject

Returns the value of attribute has_relations.



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

def has_relations
  @has_relations
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

#seqObject

Returns the value of attribute seq.



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

def seq
  @seq
end

#statusObject

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

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#subject_docObject

Returns the value of attribute subject_doc.



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

def subject_doc
  @subject_doc
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#active?Boolean



50
51
52
# File 'lib/academic_benchmarks/standards/standard.rb', line 50

def active?
  status == "Active"
end

#add_child(child) ⇒ Object

Raises:

  • (StandardError)


78
79
80
81
82
83
84
85
86
# File 'lib/academic_benchmarks/standards/standard.rb', line 78

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

#deepest?Boolean



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

def deepest?
  deepest == 'Y'
end

#has_children?Boolean



93
94
95
# File 'lib/academic_benchmarks/standards/standard.rb', line 93

def has_children?
  @children.count > 0
end

#leaf?Boolean



97
98
99
# File 'lib/academic_benchmarks/standards/standard.rb', line 97

def leaf?
  !has_children?
end

#obsolete?Boolean



54
55
56
# File 'lib/academic_benchmarks/standards/standard.rb', line 54

def obsolete?
  status == "Obsolete"
end

#remove_child(child) ⇒ Object



88
89
90
91
# File 'lib/academic_benchmarks/standards/standard.rb', line 88

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