Class: RailsXapi::Object
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RailsXapi::Object
- Defined in:
- app/models/rails_xapi/object.rb
Overview
The Object defines the thing that was acted on. See: github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#244-object The Object of a Statement can be an Activity, Agent/Group, SubStatement, or Statement Reference.
Constant Summary collapse
- OBJECT_TYPES =
%w[Activity Agent Group SubStatement StatementRef]
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
-
#context ⇒ Object
Returns the value of attribute context.
-
#object ⇒ Object
Returns the value of attribute object.
-
#objectType ⇒ Object
Returns the value of attribute objectType.
-
#result ⇒ Object
Returns the value of attribute result.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#verb ⇒ Object
Returns the value of attribute verb.
Class Method Summary collapse
-
.find_or_create(attributes) ⇒ RailsXapi::Object
Find an Object by its id or create a new one.
Instance Method Summary collapse
- #activity? ⇒ Boolean
- #as_json ⇒ Object
- #definition=(definition_hash) ⇒ Object
-
#update_definition(definition_data) ⇒ Object
Update the ActivityDefinition if it’s existing.
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def actor @actor end |
#context ⇒ Object
Returns the value of attribute context.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def context @context end |
#object ⇒ Object
Returns the value of attribute object.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def object @object end |
#objectType ⇒ Object
Returns the value of attribute objectType.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def objectType @objectType end |
#result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def result @result end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def end |
#verb ⇒ Object
Returns the value of attribute verb.
9 10 11 |
# File 'app/models/rails_xapi/object.rb', line 9 def verb @verb end |
Class Method Details
.find_or_create(attributes) ⇒ RailsXapi::Object
Find an Object by its id or create a new one.
46 47 48 |
# File 'app/models/rails_xapi/object.rb', line 46 def self.find_or_create(attributes) find_by(id: attributes[:id]) || create(attributes) end |
Instance Method Details
#activity? ⇒ Boolean
59 60 61 62 63 |
# File 'app/models/rails_xapi/object.rb', line 59 def activity? return true if object_type == "Activity" false end |
#as_json ⇒ Object
65 66 67 68 69 |
# File 'app/models/rails_xapi/object.rb', line 65 def as_json { id: id, objectType: object_type }.tap do |hash| hash[:definition] = definition.as_json if definition.present? end end |
#definition=(definition_hash) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/rails_xapi/object.rb', line 34 def definition=(definition_hash) return unless definition_hash.present? # Build or create the associated object. build_definition if definition.nil? definition.assign_from_json_definition(definition_hash) end |
#update_definition(definition_data) ⇒ Object
Update the ActivityDefinition if it’s existing.
51 52 53 54 55 56 57 |
# File 'app/models/rails_xapi/object.rb', line 51 def update_definition(definition_data) return unless definition_data.present? definition = self.definition || create_definition definition.assign_from_json_definition(definition_data) definition.save! end |