Class: TinCanApi::ActivityDefinition
- Inherits:
-
Object
- Object
- TinCanApi::ActivityDefinition
- Includes:
- InteractionType
- Defined in:
- lib/tin_can_api/activity_definition.rb
Overview
Activity Definition model class
Constant Summary
Constants included from InteractionType
InteractionType::CHOICE, InteractionType::FILL_IN, InteractionType::LIKERT, InteractionType::MATCHING, InteractionType::NUMERIC, InteractionType::OTHER, InteractionType::PERFORMANCE, InteractionType::SEQUENCING, InteractionType::TRUE_FALSE
Constants included from Enum
Instance Attribute Summary collapse
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#correct_responses_pattern ⇒ Object
Returns the value of attribute correct_responses_pattern.
-
#description ⇒ Object
Returns the value of attribute description.
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#interaction_type ⇒ Object
Returns the value of attribute interaction_type.
-
#more_info ⇒ Object
Returns the value of attribute more_info.
-
#name ⇒ Object
Returns the value of attribute name.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#source ⇒ Object
Returns the value of attribute source.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ ActivityDefinition
constructor
A new instance of ActivityDefinition.
- #serialize(version) ⇒ Object
Methods included from InteractionType
Methods included from Enum
Constructor Details
#initialize(options = {}, &block) ⇒ ActivityDefinition
Returns a new instance of ActivityDefinition.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tin_can_api/activity_definition.rb', line 11 def initialize(={}, &block) json = .fetch(:json, nil) if json attributes = JSON.parse(json) self.type = attributes['type'] if attributes['type'] self.more_info = attributes['moreInfo'] if attributes['moreInfo'] self.name = attributes['name'] if attributes['name'] self.description = attributes['description'] if attributes['description'] self.extensions = attributes['extensions'] if attributes['extensions'] self.interaction_type = attributes['interactionType'] if attributes['interactionType'] if attributes['correctResponsesPattern'] self.correct_responses_pattern = [] attributes['correctResponsesPattern'].each do |pattern| correct_responses_pattern << pattern end end if attributes['choices'] self.choices = [] attributes['choices'].each do |choice| choices << InteractionComponent.new(choice.to_json) end end if attributes['scale'] self.scale = [] attributes['scale'].each do |element| scale << InteractionComponent.new(element.to_json) end end if attributes['source'] self.source = [] attributes['source'].each do |element| source << InteractionComponent.new(element.to_json) end end if attributes['target'] self.target = [] attributes['target'].each do |element| target << InteractionComponent.new(element.to_json) end end if attributes['steps'] self.steps = [] attributes['steps'].each do |element| steps << InteractionComponent.new(element.to_json) end end else self.name = .fetch(:name, nil) self.description = .fetch(:description, nil) self.extensions = .fetch(:extensions, nil) self.interaction_type = .fetch(:interaction_type, nil) self.correct_responses_pattern = .fetch(:correct_responses_pattern, nil) self.choices = .fetch(:choices, nil) self.scale = .fetch(:scale, nil) self.source = .fetch(:source, nil) self.target = .fetch(:target, nil) self.type = .fetch(:type, nil) self.more_info = .fetch(:more_info, nil) if block_given? block[self] end end end |
Instance Attribute Details
#choices ⇒ Object
Returns the value of attribute choices.
8 9 10 |
# File 'lib/tin_can_api/activity_definition.rb', line 8 def choices @choices end |
#correct_responses_pattern ⇒ Object
Returns the value of attribute correct_responses_pattern.
7 8 9 |
# File 'lib/tin_can_api/activity_definition.rb', line 7 def correct_responses_pattern @correct_responses_pattern end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/tin_can_api/activity_definition.rb', line 7 def description @description end |
#extensions ⇒ Object
Returns the value of attribute extensions.
7 8 9 |
# File 'lib/tin_can_api/activity_definition.rb', line 7 def extensions @extensions end |
#interaction_type ⇒ Object
Returns the value of attribute interaction_type.
7 8 9 |
# File 'lib/tin_can_api/activity_definition.rb', line 7 def interaction_type @interaction_type end |
#more_info ⇒ Object
Returns the value of attribute more_info.
9 10 11 |
# File 'lib/tin_can_api/activity_definition.rb', line 9 def more_info @more_info end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/tin_can_api/activity_definition.rb', line 7 def name @name end |
#scale ⇒ Object
Returns the value of attribute scale.
8 9 10 |
# File 'lib/tin_can_api/activity_definition.rb', line 8 def scale @scale end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/tin_can_api/activity_definition.rb', line 8 def source @source end |
#steps ⇒ Object
Returns the value of attribute steps.
8 9 10 |
# File 'lib/tin_can_api/activity_definition.rb', line 8 def steps @steps end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/tin_can_api/activity_definition.rb', line 8 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/tin_can_api/activity_definition.rb', line 9 def type @type end |
Instance Method Details
#serialize(version) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/tin_can_api/activity_definition.rb', line 99 def serialize(version) 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 TinCanApi::InteractionType::CHOICE.to_s, TinCanApi::InteractionType::SEQUENCING.to_s if choices && choices.any? node['choices'] = choices.map {|element| element.serialize(version)} end when TinCanApi::InteractionType::LIKERT.to_s if scale && scale.any? node['scale'] = scale.map {|element| element.serialize(version)} end when TinCanApi::InteractionType::MATCHING.to_s if source && source.any? node['source'] = source.map {|element| element.serialize(version)} end if target && target.any? node['target'] = target.map {|element| element.serialize(version)} end when TinCanApi::InteractionType::PERFORMANCE.to_s if steps && steps.any? node['steps'] = steps.map {|element| element.serialize(version)} end end end if correct_responses_pattern && correct_responses_pattern.any? node['correctResponsesPattern'] = correct_responses_pattern.map {|element| element} end node end |