Class: ActiveLrs::Xapi::Context
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::Context
- Defined in:
- lib/active_lrs/xapi/context.rb
Overview
Represents an xAPI Context object.
A Context object provides additional information about the circumstances in which a Statement occurred. This may include registration identifiers, instructor, team, contextual activities, platform, language, revision, and extensions.
Instance Attribute Summary collapse
-
#context_activities ⇒ ContextActivity?
A set of related Activities providing context (e.g., parent course, grouping, category, or other).
-
#extensions ⇒ Hash{String => Object}?
A map of custom key/value pairs providing additional context data.
-
#instructor ⇒ Agent, ...
An Agent or Group representing the instructor.
-
#language ⇒ String?
The language code (RFC 5646) in which the experience occurred.
-
#platform ⇒ String?
A description of the system or platform used in the experience.
-
#registration ⇒ String?
A UUID identifying a registration (a series of Statements).
-
#revision ⇒ String?
Revision/version information associated with the Activity.
-
#statement ⇒ StatementRef?
A reference to another Statement.
-
#team ⇒ Group?
A Group of Agents that participated in the Statement.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new Context instance with optional attributes.
-
#to_h ⇒ Hash{String => Object}
Converts the Context object into a hash suitable for inclusion in an xAPI Statement.
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new Context instance with optional attributes.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/active_lrs/xapi/context.rb', line 58 def initialize(attributes = {}) self.registration = attributes["registration"] if attributes["registration"] self.instructor = attributes["instructor"]["member"] ? Xapi::Group.new(attributes["instructor"]) : Xapi::Agent.new(attributes["instructor"]) if attributes["instructor"] self.team = Xapi::Group.new(attributes["team"]) if attributes["team"] self.context_activities = Xapi::ContextActivities.new(attributes["contextActivities"]) if attributes["contextActivities"] self.revision = attributes["revision"] if attributes["revision"] self.platform = attributes["platform"] if attributes["platform"] self.language = attributes["language"] if attributes["language"] self.statement = Xapi::StatementRef.new(attributes["statement"]) if attributes["statement"] self.extensions = attributes["extensions"] if attributes["extensions"] end |
Instance Attribute Details
#context_activities ⇒ ContextActivity?
Returns A set of related Activities providing context (e.g., parent course, grouping, category, or other).
26 27 28 |
# File 'lib/active_lrs/xapi/context.rb', line 26 def context_activities @context_activities end |
#extensions ⇒ Hash{String => Object}?
Returns A map of custom key/value pairs providing additional context data.
42 43 44 |
# File 'lib/active_lrs/xapi/context.rb', line 42 def extensions @extensions end |
#instructor ⇒ Agent, ...
Returns An Agent or Group representing the instructor.
19 20 21 |
# File 'lib/active_lrs/xapi/context.rb', line 19 def instructor @instructor end |
#language ⇒ String?
Returns The language code (RFC 5646) in which the experience occurred.
35 36 37 |
# File 'lib/active_lrs/xapi/context.rb', line 35 def language @language end |
#platform ⇒ String?
Returns A description of the system or platform used in the experience.
32 33 34 |
# File 'lib/active_lrs/xapi/context.rb', line 32 def platform @platform end |
#registration ⇒ String?
Returns A UUID identifying a registration (a series of Statements).
16 17 18 |
# File 'lib/active_lrs/xapi/context.rb', line 16 def registration @registration end |
#revision ⇒ String?
Returns Revision/version information associated with the Activity.
29 30 31 |
# File 'lib/active_lrs/xapi/context.rb', line 29 def revision @revision end |
#statement ⇒ StatementRef?
Returns A reference to another Statement. Serialized as: { “objectType” => “StatementRef”, “id” => “<UUID>” }.
39 40 41 |
# File 'lib/active_lrs/xapi/context.rb', line 39 def statement @statement end |
#team ⇒ Group?
Returns A Group of Agents that participated in the Statement.
22 23 24 |
# File 'lib/active_lrs/xapi/context.rb', line 22 def team @team end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
Converts the Context object into a hash suitable for inclusion in an xAPI Statement.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/active_lrs/xapi/context.rb', line 86 def to_h node = {} node["registration"] = registration if registration node["instructor"] = instructor.to_h if instructor node["team"] = team.to_h if team node["contextActivities"] = context_activities.to_h if context_activities node["revision"] = revision if revision node["platform"] = platform if platform node["language"] = language if language node["statement"] = statement.to_h if statement node["extensions"] = extensions if extensions node end |