Class: ActiveLrs::Xapi::Activity
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::Activity
- Defined in:
- lib/active_lrs/xapi/activity.rb
Overview
Represents an xAPI Activity object.
An Activity is a type of xAPI Object that describes a learning activity, resource, or experience. It must have an id and an objectType of ‘“Activity”`. Optionally, it may also include a definition that provides human-readable metadata such as name, description, type, or extensions.
This class is intended for use as the object property within an xAPI Statement.
Instance Attribute Summary collapse
-
#definition ⇒ ActivityDefinition?
including human-readable name, description, type, and extensions.
-
#id ⇒ String?
uniquely identifies the Activity.
-
#object_type ⇒ String
when present, according to the xAPI specification.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new Activity instance with optional attributes.
-
#to_h ⇒ Hash{String => Object}
Converts the Activity object into a hash representation suitable for serialization in an xAPI Statement.
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new Activity instance with optional attributes.
42 43 44 45 46 |
# File 'lib/active_lrs/xapi/activity.rb', line 42 def initialize(attributes = {}) @object_type = "Activity" self.id = attributes["id"] if attributes["id"] self.definition = ActivityDefinition.new(attributes["definition"]) if attributes["definition"] end |
Instance Attribute Details
#definition ⇒ ActivityDefinition?
including human-readable name, description, type, and extensions.
29 30 31 |
# File 'lib/active_lrs/xapi/activity.rb', line 29 def definition @definition end |
#id ⇒ String?
uniquely identifies the Activity.
21 22 23 |
# File 'lib/active_lrs/xapi/activity.rb', line 21 def id @id end |
#object_type ⇒ String
when present, according to the xAPI specification.
25 26 27 |
# File 'lib/active_lrs/xapi/activity.rb', line 25 def object_type @object_type end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
Converts the Activity object into a hash representation suitable for serialization in an xAPI Statement.
66 67 68 69 70 71 72 |
# File 'lib/active_lrs/xapi/activity.rb', line 66 def to_h node = {} node["objectType"] = object_type node["id"] = id.to_s if id node["definition"] = definition.to_h if definition node end |