Class: TinCanApi::Statements::StatementsBase
- Inherits:
-
Object
- Object
- TinCanApi::Statements::StatementsBase
- Defined in:
- lib/tin_can_api/statements/statements_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#context ⇒ Object
Returns the value of attribute context.
-
#object ⇒ Object
Returns the value of attribute object.
-
#result ⇒ Object
Returns the value of attribute result.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#verb ⇒ Object
Returns the value of attribute verb.
-
#voided ⇒ Object
Returns the value of attribute voided.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ StatementsBase
constructor
A new instance of StatementsBase.
- #serialize(version) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ StatementsBase
Returns a new instance of StatementsBase.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 8 def initialize(={}, &block) @attachments = [] json = .fetch(:json, nil) if json attributes = JSON.parse(json) self.actor = TinCanApi::Agent.new(json: attributes['actor'].to_json) if attributes['actor'] self.verb = TinCanApi::Verb.new(json: attributes['verb'].to_json) if attributes['verb'] object_node = attributes['object'] if object_node case object_node['objectType'] when 'Group', 'Agent' self.object = TinCanApi::Agent.new(json: object_node.to_json) when 'StatementRef' self.object = TinCanApi::StatementRef.new(json: object_node.to_json) when 'SubStatement' self.object = TinCanApi::SubStatement.new(json: object_node.to_json) else self.object = TinCanApi::Activity.new(json: object_node.to_json) end end self.result = TinCanApi::Result.new(json: attributes['result'].to_json) if attributes['result'] self.context = TinCanApi::Context.new(json: attributes['context'].to_json) if attributes['context'] self. = Time.parse(attributes['timestamp']) if attributes['timestamp'] self.voided = attributes['voided'] if attributes['voided'] if attributes['attachments'] attributes['attachments'].each do || << TinCanApi::Attachment.new(json: .to_json) end end else self.actor = .fetch(:actor, nil) self.verb = .fetch(:verb, nil) self.object = .fetch(:object, nil) self.result = .fetch(:result, nil) self.context = .fetch(:context, nil) self. = .fetch(:timestamp, nil) self. = .fetch(:attachments, nil) self.voided = .fetch(:voided, nil) if block_given? block[self] end end end |
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def actor @actor end |
#attachments ⇒ Object
Returns the value of attribute attachments.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def @attachments end |
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def context @context end |
#object ⇒ Object
Returns the value of attribute object.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def object @object end |
#result ⇒ Object
Returns the value of attribute result.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def result @result end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def @timestamp end |
#verb ⇒ Object
Returns the value of attribute verb.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def verb @verb end |
#voided ⇒ Object
Returns the value of attribute voided.
6 7 8 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 6 def voided @voided end |
Instance Method Details
#serialize(version) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tin_can_api/statements/statements_base.rb', line 53 def serialize(version) node = {} node['actor'] = actor.serialize(version) node['verb'] = verb.serialize(version) node['object'] = object.serialize(version) node['result'] = result.serialize(version) if result node['context'] = context.serialize(version) if context node['timestamp'] = .strftime('%FT%T%:z') if if version.ordinal <= TinCanApi::TCAPIVersion::V100.ordinal if && .any? node['attachments'] = .map {|element| element.serialize(version)} end end node end |