Class: ActiveLrs::Xapi::InteractionComponent
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::InteractionComponent
- Includes:
- LocalizationHelper
- Defined in:
- lib/active_lrs/xapi/interaction_component.rb
Overview
Represents an xAPI Interaction Component.
Interaction components are used in certain ActivityDefinitions where an interactionType is specified (e.g. multiple choice, sequencing, matching, etc.). They describe the options or elements involved (choices, scale steps, source/target, etc.). Each component must have an id, and may include a description map.
Instance Attribute Summary collapse
-
#description ⇒ Hash{String => String}?
A language map providing a human-readable description of the component (optional).
-
#id ⇒ String
The identifier for this component (required).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new InteractionComponent instance with optional attributes.
-
#localize_description(locale: nil) ⇒ String
Returns the localized description of the interaction component.
-
#to_h ⇒ Hash{String => (String, Hash)}
Converts the InteractionComponent into a hash form suitable for inclusion in an ActivityDefinition interactionType component list.
Methods included from LocalizationHelper
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new InteractionComponent instance with optional attributes.
32 33 34 35 |
# File 'lib/active_lrs/xapi/interaction_component.rb', line 32 def initialize(attributes = {}) self.id = attributes["id"] if attributes["id"] self.description = attributes["description"] if attributes["description"] end |
Instance Attribute Details
#description ⇒ Hash{String => String}?
Returns A language map providing a human-readable description of the component (optional).
23 24 25 |
# File 'lib/active_lrs/xapi/interaction_component.rb', line 23 def description @description end |
#id ⇒ String
Returns The identifier for this component (required).
19 20 21 |
# File 'lib/active_lrs/xapi/interaction_component.rb', line 19 def id @id end |
Instance Method Details
#localize_description(locale: nil) ⇒ String
Returns the localized description of the interaction component.
60 61 62 |
# File 'lib/active_lrs/xapi/interaction_component.rb', line 60 def localize_description(locale: nil) get_localized_value(description, locale) end |
#to_h ⇒ Hash{String => (String, Hash)}
Converts the InteractionComponent into a hash form suitable for inclusion in an ActivityDefinition interactionType component list.
49 50 51 52 53 54 |
# File 'lib/active_lrs/xapi/interaction_component.rb', line 49 def to_h node = {} node["id"] = id if id node["description"] = description if description node end |