Class: Xapi::Result
- Inherits:
-
Object
- Object
- Xapi::Result
- Defined in:
- lib/xapi/result.rb
Overview
Result Model class
Instance Attribute Summary collapse
-
#completion ⇒ Object
Returns the value of attribute completion.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#response ⇒ Object
Returns the value of attribute response.
-
#score ⇒ Object
Returns the value of attribute score.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Result
constructor
A new instance of Result.
- #serialize(version) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Result
Returns a new instance of Result.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xapi/result.rb', line 10 def initialize(={}, &block) json = .fetch(:json, nil) if json attributes = JSON.parse(json) self.score = Xapi::Score.new(json: attributes['score'].to_json) if attributes['score'] self.success = attributes['success'] unless attributes['success'].nil? self.completion = attributes['completion'] unless attributes['completion'].nil? self.duration = ActiveSupport::Duration.parse(attributes['duration']) if attributes['duration'] self.response = attributes['response'] if attributes['response'] self.extensions = attributes['extensions'] if attributes['extensions'] else self.score = .fetch(:score, nil) self.success = .fetch(:success, nil) self.completion = .fetch(:completion, nil) self.duration = .fetch(:duration, nil) self.response = .fetch(:response, nil) self.extensions = .fetch(:extensions, nil) if block_given? block[self] end end end |
Instance Attribute Details
#completion ⇒ Object
Returns the value of attribute completion.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def completion @completion end |
#duration ⇒ Object
Returns the value of attribute duration.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def duration @duration end |
#extensions ⇒ Object
Returns the value of attribute extensions.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def extensions @extensions end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def response @response end |
#score ⇒ Object
Returns the value of attribute score.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def score @score end |
#success ⇒ Object
Returns the value of attribute success.
8 9 10 |
# File 'lib/xapi/result.rb', line 8 def success @success end |
Instance Method Details
#serialize(version) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xapi/result.rb', line 34 def serialize(version) node = {} node['score'] = score.serialize(version) if score node['success'] = success unless success.nil? node['completion'] = completion unless completion.nil? node['duration'] = duration.iso8601 if duration node['response'] = response if response node['extensions'] = extensions if extensions node end |