Class: ActiveLrs::Xapi::ContextActivities
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::ContextActivities
- Defined in:
- lib/active_lrs/xapi/context_activities.rb
Overview
Represents an xAPI ContextActivities object.
ContextActivities provide contextual information about the Activity related to a Statement. They allow grouping, categorization, or relationships to other Activities.
Each property is an array of Activity objects.
Instance Attribute Summary collapse
-
#category ⇒ Array<Activity>?
A categorization tag indicating a profile or context (e.g., “SCORM profile”, “performance review”).
-
#grouping ⇒ Array<Activity>?
Activities used to group Statements for reporting purposes (e.g., “Unit 1” grouping multiple lessons).
-
#other ⇒ Array<Activity>?
Any other contextually relevant Activities not covered by parent, grouping, or category.
-
#parent ⇒ Array<Activity>?
A parent Activity with a more general scope than the Statement’s object Activity (e.g., “Course” as parent of “Lesson”).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new ContextActivity instance with optional context activity attributes.
-
#to_h ⇒ Hash{String => Array<Hash>}
Converts the ContextActivity into a hash suitable for inclusion in an xAPI Statement.
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new ContextActivity instance with optional context activity attributes.
40 41 42 43 44 45 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 40 def initialize(attributes = {}) self.parent = Array(attributes["parent"]).map { |element| Activity.new(element) } if attributes["parent"] self.grouping = Array(attributes["grouping"]).map { |element| Activity.new(element) } if attributes["grouping"] self.other = Array(attributes["other"]).map { |element| Activity.new(element) } if attributes["other"] self.category = Array(attributes["category"]).map { |element| Activity.new(element) } if attributes["category"] end |
Instance Attribute Details
#category ⇒ Array<Activity>?
Returns A categorization tag indicating a profile or context (e.g., “SCORM profile”, “performance review”).
25 26 27 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 25 def category @category end |
#grouping ⇒ Array<Activity>?
Returns Activities used to group Statements for reporting purposes (e.g., “Unit 1” grouping multiple lessons).
21 22 23 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 21 def grouping @grouping end |
#other ⇒ Array<Activity>?
Returns Any other contextually relevant Activities not covered by parent, grouping, or category.
29 30 31 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 29 def other @other end |
#parent ⇒ Array<Activity>?
Returns A parent Activity with a more general scope than the Statement’s object Activity (e.g., “Course” as parent of “Lesson”).
17 18 19 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 17 def parent @parent end |
Instance Method Details
#to_h ⇒ Hash{String => Array<Hash>}
Converts the ContextActivity into a hash suitable for inclusion in an xAPI Statement.
61 62 63 64 65 66 67 68 |
# File 'lib/active_lrs/xapi/context_activities.rb', line 61 def to_h node = {} node["parent"] = parent.map { |element| element.to_h } if parent && parent.any? node["grouping"] = grouping.map { |element| element.to_h } if grouping && grouping.any? node["other"] = other.map { |element| element.to_h } if other && other.any? node["category"] = category.map { |element| element.to_h } if category && category.any? node end |