class Xapi::Result
Result
Model class
Attributes
completion[RW]
duration[RW]
extensions[RW]
response[RW]
score[RW]
success[RW]
Public Class Methods
new(options={}, &block)
click to toggle source
# File lib/xapi/result.rb, line 10 def initialize(options={}, &block) json = options.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 = options.fetch(:score, nil) self.success = options.fetch(:success, nil) self.completion = options.fetch(:completion, nil) self.duration = options.fetch(:duration, nil) self.response = options.fetch(:response, nil) self.extensions = options.fetch(:extensions, nil) if block_given? block[self] end end end
Public Instance Methods
serialize(version)
click to toggle source
# 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