Class: ActiveLrs::Xapi::StatementRef

Inherits:
Object
  • Object
show all
Defined in:
lib/active_lrs/xapi/statement_ref.rb

Overview

Represents an xAPI StatementRef object.

A StatementRef allows one Statement to refer to another Statement by its id. This is useful for embedding or linking statements without duplicating all data. Typically used in the object property of a Statement.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ void

Initializes a new StatementRef.

Parameters:

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

    Attributes hash containing id.

Options Hash (attributes):

  • "id" (String)

    The ID of the statement to reference (required).



26
27
28
29
# File 'lib/active_lrs/xapi/statement_ref.rb', line 26

def initialize(attributes = {})
  @object_type = "StatementRef"
  self.id = attributes["id"] if attributes["id"]
end

Instance Attribute Details

#idString

Returns The ID of the referenced statement.

Returns:

  • (String)

    The ID of the referenced statement.



18
19
20
# File 'lib/active_lrs/xapi/statement_ref.rb', line 18

def id
  @id
end

#object_typeString

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

Returns:

  • (String)

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



15
16
17
# File 'lib/active_lrs/xapi/statement_ref.rb', line 15

def object_type
  @object_type
end

Instance Method Details

#to_hHash{String => String}

Converts the StatementRef into a hash suitable for use as the object of a Statement.

Examples:

ref = ActiveLrs::Xapi::StatementRef.new("id" => "123e4567-e89b-12d3-a456-426614174000")
ref.to_h
# => { "objectType" => "StatementRef", "id" => "123e4567-e89b-12d3-a456-426614174000" }

Returns:

  • (Hash{String => String})

    A hash with objectType and id.



39
40
41
42
43
44
# File 'lib/active_lrs/xapi/statement_ref.rb', line 39

def to_h
  node = {}
  node["id"] = id if id
  node["objectType"] = object_type
  node
end