Class: TinCanApi::Statement
- Inherits:
-
TinCanApi::Statements::StatementsBase
- Object
- TinCanApi::Statements::StatementsBase
- TinCanApi::Statement
- Defined in:
- lib/tin_can_api/statement.rb
Overview
Statement Class
Instance Attribute Summary collapse
-
#authority ⇒ Object
Returns the value of attribute authority.
-
#id ⇒ Object
Returns the value of attribute id.
-
#stored ⇒ Object
Returns the value of attribute stored.
-
#version ⇒ Object
Returns the value of attribute version.
-
#voided ⇒ Object
Returns the value of attribute voided.
Attributes inherited from TinCanApi::Statements::StatementsBase
#actor, #attachments, #context, #object, #result, #timestamp, #verb
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Statement
constructor
A new instance of Statement.
- #serialize(version) ⇒ Object
- #stamp ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Statement
Returns a new instance of Statement.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tin_can_api/statement.rb', line 8 def initialize(={}, &block) super(, &block) json = .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. = TinCanApi::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 = .fetch(:id, nil) self.stored = .fetch(:stored, nil) self. = .fetch(:authority, nil) self.version = .fetch(:version, nil) self.voided = .fetch(:voided, nil) if block_given? block[self] end end end |
Instance Attribute Details
#authority ⇒ Object
Returns the value of attribute authority.
6 7 8 |
# File 'lib/tin_can_api/statement.rb', line 6 def @authority end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/tin_can_api/statement.rb', line 6 def id @id end |
#stored ⇒ Object
Returns the value of attribute stored.
6 7 8 |
# File 'lib/tin_can_api/statement.rb', line 6 def stored @stored end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/tin_can_api/statement.rb', line 6 def version @version end |
#voided ⇒ Object
Returns the value of attribute voided.
6 7 8 |
# File 'lib/tin_can_api/statement.rb', line 6 def voided @voided end |
Instance Method Details
#serialize(version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tin_can_api/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'] = .serialize(version) if if version == TinCanApi::TCAPIVersion::V095 node['voided'] = voided if voided end if version.ordinal <= TinCanApi::TCAPIVersion::V100.ordinal node['version'] = version.to_s if version end node end |
#stamp ⇒ Object
48 49 50 51 |
# File 'lib/tin_can_api/statement.rb', line 48 def stamp @id = SecureRandom.uuid @timestamp = Time.now end |