Class: RailsXapi::InteractionActivity
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RailsXapi::InteractionActivity
- Defined in:
- app/models/rails_xapi/interaction_activity.rb
Overview
The optional structure for interactions or assessments. See: github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#interaction-activities
Constant Summary collapse
- INTERACTION_COMPONENT_TYPES =
%w[scale choices source target steps]
- INTERACTION_KEYS =
%w[interactionType correctResponsesPattern] + INTERACTION_COMPONENT_TYPES
Instance Method Summary collapse
- #as_json ⇒ Object
- #assign_interaction_components(interaction_attrs) ⇒ Object
- #components_by_interaction_type ⇒ Object
- #correct_responses_pattern ⇒ Object
- #correct_responses_pattern=(value) ⇒ Object
Instance Method Details
#as_json ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/rails_xapi/interaction_activity.rb', line 72 def as_json { interactionType: interaction_type, correctResponsesPattern: correct_responses_pattern }.merge(components_by_interaction_type) end |
#assign_interaction_components(interaction_attrs) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/rails_xapi/interaction_activity.rb', line 34 def assign_interaction_components(interaction_attrs) return unless interaction_attrs.present? interaction_components.where( component_type: INTERACTION_COMPONENT_TYPES ).destroy_all INTERACTION_COMPONENT_TYPES.each do |component_type| Array(interaction_attrs[component_type]).each do |data| interaction_components.build( component_type: component_type, component_id: data["id"], description: data["description"].to_json, interaction_activity: self ) end end end |
#components_by_interaction_type ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/rails_xapi/interaction_activity.rb', line 61 def components_by_interaction_type case interaction_type when "likert" { "scale" => component_hash } when "choice" { "choice" => component_hash } else {} end end |
#correct_responses_pattern ⇒ Object
53 54 55 |
# File 'app/models/rails_xapi/interaction_activity.rb', line 53 def correct_responses_pattern JSON.parse(super || "[]") end |
#correct_responses_pattern=(value) ⇒ Object
57 58 59 |
# File 'app/models/rails_xapi/interaction_activity.rb', line 57 def correct_responses_pattern=(value) super(value.to_json) end |