Class: ActiveLrs::Xapi::SubStatement

Inherits:
#StatementBase
  • Object
show all
Defined in:
lib/active_lrs/xapi/sub_statement.rb

Overview

Represents an xAPI SubStatement object.

A SubStatement is like a normal Statement but **cannot have its own id, authority, or stored information**. SubStatements are typically used as the object property inside another Statement or SubStatement.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ void

Initializes a new SubStatement.

Parameters:

  • attributes (Hash) (defaults to: {})

    Attributes for the SubStatement

Options Hash (attributes):

  • "actor" (Hash)

    Actor information (Agent or Group)

  • "verb" (Hash)

    Verb information

  • "object" (Hash)

    Object information (Activity, Agent, Group, StatementRef, SubStatement)

  • "result" (Hash)

    Optional result of the activity

  • "context" (Hash)

    Optional context providing additional info

  • "timestamp" (String)

    ISO 8601 timestamp



27
28
29
30
# File 'lib/active_lrs/xapi/sub_statement.rb', line 27

def initialize(attributes = {})
  @object_type = "SubStatement"
  super(attributes)
end

Instance Attribute Details

#object_typeString

Returns The object type. MUST be the literal string ‘“SubStatement”`.

Returns:

  • (String)

    The object type. MUST be the literal string ‘“SubStatement”`.



14
15
16
# File 'lib/active_lrs/xapi/sub_statement.rb', line 14

def object_type
  @object_type
end

Instance Method Details

#to_hHash{String => Object}

Converts the SubStatement into a hash suitable for inclusion as an object in another Statement.

Examples:

sub = ActiveLrs::Xapi::SubStatement.new(
  "actor" => { "mbox" => "mailto:[email protected]" },
  "verb" => { "id" => "http://adlnet.gov/expapi/verbs/attempted" },
  "object" => { "id" => "http://example.com/course/2" }
)
sub.to_h
# => {
#   "objectType" => "SubStatement",
#   "actor" => { "objectType" => "Agent", "mbox" => "mailto:[email protected]" },
#   "verb" => { "id" => "http://adlnet.gov/expapi/verbs/attempted" },
#   "object" => { "id" => "http://example.com/course/2", "objectType" => "Activity" }
# }

Returns:

  • (Hash{String => Object})

    A hash representation of the SubStatement



49
50
51
52
53
# File 'lib/active_lrs/xapi/sub_statement.rb', line 49

def to_h
  node = super
  node["objectType"] = object_type
  node
end