Class: ActiveLrs::Xapi::ActivityDefinition
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::ActivityDefinition
- Includes:
- LocalizationHelper
- Defined in:
- lib/active_lrs/xapi/activity_definition.rb
Overview
Represents an xAPI ActivityDefinition object.
ActivityDefinition provides metadata for an Activity. It describes the nature, type, and content of the activity, including human-readable labels, interaction type, scoring, and other extensions.
Instance Attribute Summary collapse
-
#choices ⇒ Array<InteractionComponent>?
Choices for ‘choice’ interaction types.
-
#correct_responses_pattern ⇒ Array<String>?
Correct response patterns for interaction activities.
-
#description ⇒ Hash{String => String}?
Language map for the activity’s description.
-
#extensions ⇒ Hash{String => Object}?
Extensions for additional metadata.
-
#interaction_type ⇒ String?
The interaction type for interaction activities (e.g., ‘choice’, ‘sequencing’, ‘likert’, etc.).
-
#more_info ⇒ String?
human-readable information about the Activity.
-
#name ⇒ Hash{String => String}?
Language map for the activity’s name.
-
#scale ⇒ Array<InteractionComponent>?
Scale for ‘scale’ interaction types.
-
#source ⇒ Array<InteractionComponent>?
Source components for ‘matching’ interaction types.
-
#steps ⇒ Array<InteractionComponent>?
Steps for ‘sequencing’ interaction types.
-
#target ⇒ Array<InteractionComponent>?
Target components for ‘matching’ interaction types.
-
#type ⇒ String?
The activity type as an IRI (e.g., adlnet.gov/expapi/activities/course).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new ActivityDefinition instance.
-
#localize_description(locale: nil) ⇒ String
Returns the localized description of the activity.
-
#localize_name(locale: nil) ⇒ String
Returns the localized name of the activity.
-
#to_h ⇒ Hash{String => Object}
Converts the ActivityDefinition into a hash suitable for inclusion in an xAPI Activity object.
Methods included from LocalizationHelper
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new ActivityDefinition instance.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 72 def initialize(attributes = {}) self.name = attributes["name"] if attributes["name"] self.description = attributes["description"] if attributes["description"] self.type = attributes["type"] if attributes["type"] self.more_info = attributes["moreInfo"] if attributes["moreInfo"] self.interaction_type = attributes["interactionType"] if attributes["interactionType"] self.correct_responses_pattern = attributes["correctResponsesPattern"] if attributes["correctResponsesPattern"] self.choices = attributes["choices"]&.map { |choice| InteractionComponent.new(choice) } self.scale = attributes["scale"]&.map { |scale| InteractionComponent.new(scale) } self.source = attributes["source"]&.map { |source| InteractionComponent.new(source) } self.target = attributes["target"]&.map { |target| InteractionComponent.new(target) } self.steps = attributes["steps"]&.map { |step| InteractionComponent.new(step) } self.extensions = attributes["extensions"] if attributes["extensions"] end |
Instance Attribute Details
#choices ⇒ Array<InteractionComponent>?
38 39 40 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 38 def choices @choices end |
#correct_responses_pattern ⇒ Array<String>?
35 36 37 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 35 def correct_responses_pattern @correct_responses_pattern end |
#description ⇒ Hash{String => String}?
20 21 22 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 20 def description @description end |
#extensions ⇒ Hash{String => Object}?
53 54 55 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 53 def extensions @extensions end |
#interaction_type ⇒ String?
32 33 34 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 32 def interaction_type @interaction_type end |
#more_info ⇒ String?
human-readable information about the Activity. This may include instructions, descriptions, or a way to launch the activity.
28 29 30 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 28 def more_info @more_info end |
#name ⇒ Hash{String => String}?
17 18 19 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 17 def name @name end |
#scale ⇒ Array<InteractionComponent>?
41 42 43 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 41 def scale @scale end |
#source ⇒ Array<InteractionComponent>?
44 45 46 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 44 def source @source end |
#steps ⇒ Array<InteractionComponent>?
50 51 52 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 50 def steps @steps end |
#target ⇒ Array<InteractionComponent>?
47 48 49 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 47 def target @target end |
#type ⇒ String?
23 24 25 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 23 def type @type end |
Instance Method Details
#localize_description(locale: nil) ⇒ String
Returns the localized description of the activity.
159 160 161 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 159 def localize_description(locale: nil) get_localized_value(description, locale) end |
#localize_name(locale: nil) ⇒ String
Returns the localized name of the activity.
151 152 153 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 151 def localize_name(locale: nil) get_localized_value(name, locale) end |
#to_h ⇒ Hash{String => Object}
Converts the ActivityDefinition into a hash suitable for inclusion in an xAPI Activity object.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/active_lrs/xapi/activity_definition.rb', line 118 def to_h node = {} node["name"] = name if name node["description"] = description if description node["type"] = type.to_s if type node["moreInfo"] = more_info.to_s if more_info node["extensions"] = extensions if extensions if interaction_type node["interactionType"] = interaction_type.to_s case interaction_type when "choice", "sequencing" node["choices"] = choices.map { |element| element.to_h } if choices && choices.any? when "likert" node["scale"] = scale.map { |element| element.to_h } if scale && scale.any? when "matching" node["source"] = source.map { |element| element.to_h } if source && source.any? node["target"] = target.map { |element| element.to_h } if target && target.any? when "performance" node["steps"] = steps.map { |element| element.to_h } if steps && steps.any? end end if correct_responses_pattern&.any? node["correctResponsesPattern"] = correct_responses_pattern.map { |element| element } end node end |