class Xapi::Statement
Statement
Class
Attributes
id[RW]
stored[RW]
version[RW]
voided[RW]
Public Class Methods
new(options={}, &block)
click to toggle source
Calls superclass method
# File lib/xapi/statement.rb, line 8 def initialize(options={}, &block) super(options, &block) json = options.fetch(:json, nil) if json attributes = JSON.parse(json) self.id = attributes['id'] if attributes['id'] self.stored = Time.parse(attributes['stored']) if attributes['stored'] self.authority = Xapi::Agent.new(json: attributes['authority'].to_json) if attributes['authority'] self.version = attributes['version'] if attributes['version'] self.voided = attributes['voided'] if attributes['voided'] else self.id = options.fetch(:id, nil) self.stored = options.fetch(:stored, nil) self.authority = options.fetch(:authority, nil) self.version = options.fetch(:version, nil) self.voided = options.fetch(:voided, nil) if block_given? block[self] end end end
Public Instance Methods
serialize(version)
click to toggle source
Calls superclass method
# File lib/xapi/statement.rb, line 31 def serialize(version) node = super(version) node['id'] = id if id node['stored'] = stored.strftime('%FT%T%:z') if stored node['authority'] = authority.serialize(version) if authority if version == Xapi::TCAPIVersion::V095 node['voided'] = voided if voided end if version.ordinal >= Xapi::TCAPIVersion::V100.ordinal node['version'] = version.to_s if version end node end
stamp(id: SecureRandom.uuid, timestamp: Time.now)
click to toggle source
# File lib/xapi/statement.rb, line 48 def stamp(id: SecureRandom.uuid, timestamp: Time.now) @id = id @timestamp = timestamp end