Class: ActiveLrs::Xapi::Result
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::Result
- Defined in:
- lib/active_lrs/xapi/result.rb
Overview
Represents an xAPI Result object.
The Result object captures the outcome of an Activity. It may include scoring, completion status, success, learner response, duration, and additional extensions.
Instance Attribute Summary collapse
-
#completion ⇒ Boolean?
True if the Activity was completed (optional).
-
#duration ⇒ String?
ISO 8601 duration string representing the time spent (optional).
-
#extensions ⇒ Hash{String => Object}?
Additional metadata not covered by standard properties.
-
#response ⇒ String?
Learner’s response, e.g., entered text or choice (optional).
-
#score ⇒ Score?
The score achieved for the Activity (optional).
-
#success ⇒ Boolean?
True if the Activity was successfully completed (optional).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new Result instance.
-
#to_h ⇒ Hash{String => Object}
Converts the Result object into a hash suitable for inclusion in an xAPI Statement.
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new Result instance.
45 46 47 48 49 50 51 52 |
# File 'lib/active_lrs/xapi/result.rb', line 45 def initialize(attributes = {}) self.score = Xapi::Score.new(attributes["score"]) if attributes["score"] self.success = attributes["success"] unless attributes["success"].nil? self.completion = attributes["completion"] unless attributes["completion"].nil? self.duration = attributes["duration"] if attributes["duration"] self.response = attributes["response"] if attributes["response"] self.extensions = attributes["extensions"] if attributes["extensions"] end |
Instance Attribute Details
#completion ⇒ Boolean?
Returns True if the Activity was completed (optional).
23 24 25 |
# File 'lib/active_lrs/xapi/result.rb', line 23 def completion @completion end |
#duration ⇒ String?
Returns ISO 8601 duration string representing the time spent (optional).
29 30 31 |
# File 'lib/active_lrs/xapi/result.rb', line 29 def duration @duration end |
#extensions ⇒ Hash{String => Object}?
Returns Additional metadata not covered by standard properties.
32 33 34 |
# File 'lib/active_lrs/xapi/result.rb', line 32 def extensions @extensions end |
#response ⇒ String?
Returns Learner’s response, e.g., entered text or choice (optional).
26 27 28 |
# File 'lib/active_lrs/xapi/result.rb', line 26 def response @response end |
#score ⇒ Score?
Returns The score achieved for the Activity (optional).
17 18 19 |
# File 'lib/active_lrs/xapi/result.rb', line 17 def score @score end |
#success ⇒ Boolean?
Returns True if the Activity was successfully completed (optional).
20 21 22 |
# File 'lib/active_lrs/xapi/result.rb', line 20 def success @success end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
Converts the Result object into a hash suitable for inclusion in an xAPI Statement.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_lrs/xapi/result.rb', line 76 def to_h node = {} node["score"] = score.to_h if score node["success"] = success unless success.nil? node["completion"] = completion unless completion.nil? node["response"] = response if response node["duration"] = format_duration(duration) if duration node["extensions"] = extensions if extensions node end |