Class: TinCanApi::Result
- Inherits:
-
Object
- Object
- TinCanApi::Result
- Defined in:
- lib/tin_can_api/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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tin_can_api/result.rb', line 9 def initialize(={}, &block) json = .fetch(:json, nil) if json attributes = JSON.parse(json) self.score = TinCanApi::Score.new(json: attributes['score'].to_json) if attributes['score'] self.success = attributes['success'] if attributes['success'] self.completion = attributes['completion'] if attributes['completion'] self.duration = Duration.new(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.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def completion @completion end |
#duration ⇒ Object
Returns the value of attribute duration.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def duration @duration end |
#extensions ⇒ Object
Returns the value of attribute extensions.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def extensions @extensions end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def response @response end |
#score ⇒ Object
Returns the value of attribute score.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def score @score end |
#success ⇒ Object
Returns the value of attribute success.
7 8 9 |
# File 'lib/tin_can_api/result.rb', line 7 def success @success end |
Instance Method Details
#serialize(version) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tin_can_api/result.rb', line 33 def serialize(version) node = {} node['score'] = score.serialize(version) if score node['success'] = success if success node['completion'] = completion if completion node['duration'] = duration.iso8601 if duration node['response'] = response if response node['extensions'] = extensions if extensions node end |