Class: AcademicBenchmarks::Standards::Standard
- Inherits:
-
Object
- Object
- AcademicBenchmarks::Standards::Standard
- Includes:
- InstVarsToHash, RemoveObsoleteChildren
- Defined in:
- lib/academic_benchmarks/standards/standard.rb
Instance Attribute Summary collapse
-
#adopt_year ⇒ Object
Returns the value of attribute adopt_year.
-
#authority ⇒ Object
Returns the value of attribute authority.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#course ⇒ Object
Returns the value of attribute course.
-
#deepest ⇒ Object
Returns the value of attribute deepest.
-
#description ⇒ Object
(also: #descr)
Returns the value of attribute description.
-
#document ⇒ Object
Returns the value of attribute document.
- #grade ⇒ Object
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#has_relations ⇒ Object
Returns the value of attribute has_relations.
-
#label ⇒ Object
Returns the value of attribute label.
-
#level ⇒ Object
Returns the value of attribute level.
-
#number ⇒ Object
Returns the value of attribute number.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parent_guid ⇒ Object
Returns the value of attribute parent_guid.
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#status ⇒ Object
Returns the value of attribute status.
-
#stem ⇒ Object
Returns the value of attribute stem.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#subject_doc ⇒ Object
Returns the value of attribute subject_doc.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add_child(child) ⇒ Object
- #deepest? ⇒ Boolean
- #has_children? ⇒ Boolean
-
#initialize(data) ⇒ Standard
(also: #from_hash)
constructor
A new instance of Standard.
- #leaf? ⇒ Boolean
- #obsolete? ⇒ Boolean
- #remove_child(child) ⇒ Object
Methods included from RemoveObsoleteChildren
Methods included from InstVarsToHash
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") = 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_year ⇒ Object
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 |
#authority ⇒ Object
Returns the value of attribute authority.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
10 11 12 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 10 def children @children end |
#course ⇒ Object
Returns the value of attribute course.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def course @course end |
#deepest ⇒ Object
Returns the value of attribute deepest.
10 11 12 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 10 def deepest @deepest end |
#description ⇒ Object 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 |
#document ⇒ Object
Returns the value of attribute document.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def document @document end |
#grade ⇒ Object
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 |
#guid ⇒ Object
Returns the value of attribute guid.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def guid @guid end |
#has_relations ⇒ Object
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 |
#label ⇒ Object
Returns the value of attribute label.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def label @label end |
#level ⇒ Object
Returns the value of attribute level.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def level @level end |
#number ⇒ Object
Returns the value of attribute number.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def number @number end |
#parent ⇒ Object
Returns the value of attribute parent.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def parent @parent end |
#parent_guid ⇒ Object
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 |
#seq ⇒ Object
Returns the value of attribute seq.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def seq @seq end |
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 10 def status @status end |
#stem ⇒ Object
Returns the value of attribute stem.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def stem @stem end |
#subject ⇒ Object
Returns the value of attribute subject.
12 13 14 |
# File 'lib/academic_benchmarks/standards/standard.rb', line 12 def subject @subject end |
#subject_doc ⇒ Object
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 |
#version ⇒ Object
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
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 |