Class: ActiveLrs::Xapi::Agent

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

Overview

Represents an xAPI Agent object.

An Agent identifies an individual (person) associated with an xAPI Statement. An Agent can be uniquely identified using one of the Inverse Functional Identifier (IFI) fields: mbox, mbox_sha1sum, openid, or account.

This class is intended for use as the actor or object property within an xAPI Statement.

Direct Known Subclasses

Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ void

Initializes a new Agent instance with optional attributes.

Parameters:

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

    a hash of agent attributes

Options Hash (attributes):

  • "name" (String)

    The human-readable name of the Agent.

  • "mbox" (String)

    A “mailto:” IRI identifying the Agent’s email address.

  • "mbox_sha1sum" (String)

    The SHA1 hash of a “mailto:” IRI.

  • "openid" (String)

    An OpenID URI that uniquely identifies the Agent.

  • "account" (Hash)

    A hash representing the AgentAccount (keys: “homePage”, “name”).



48
49
50
51
52
53
54
55
# File 'lib/active_lrs/xapi/agent.rb', line 48

def initialize(attributes = {})
  @object_type = "Agent"
  self.name = attributes["name"] if attributes["name"]
  self.mbox = attributes["mbox"] if attributes["mbox"]
  self.mbox_sha1_sum = attributes["mbox_sha1sum"] if attributes["mbox_sha1sum"]
  self.open_id = attributes["openid"] if attributes["openid"]
  self. = Xapi::AgentAccount.new(attributes["account"]) if attributes["account"]
end

Instance Attribute Details

#accountAgentAccount?

Returns An account object uniquely identifying the Agent within a given system.

Returns:

  • (AgentAccount, nil)

    An account object uniquely identifying the Agent within a given system.



32
33
34
# File 'lib/active_lrs/xapi/agent.rb', line 32

def 
  @account
end

#mboxString?

Returns A “mailto:” IRI identifying the Agent’s email address.

Returns:

  • (String, nil)

    A “mailto:” IRI identifying the Agent’s email address.



22
23
24
# File 'lib/active_lrs/xapi/agent.rb', line 22

def mbox
  @mbox
end

#mbox_sha1_sumString?

Returns The SHA1 hash of a “mailto:” IRI.

Returns:

  • (String, nil)

    The SHA1 hash of a “mailto:” IRI.



25
26
27
# File 'lib/active_lrs/xapi/agent.rb', line 25

def mbox_sha1_sum
  @mbox_sha1_sum
end

#nameString?

Returns The full name of the Agent (human-readable).

Returns:

  • (String, nil)

    The full name of the Agent (human-readable).



19
20
21
# File 'lib/active_lrs/xapi/agent.rb', line 19

def name
  @name
end

#object_typeString

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

Returns:

  • (String)

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



35
36
37
# File 'lib/active_lrs/xapi/agent.rb', line 35

def object_type
  @object_type
end

#open_idString?

Returns An OpenID URI that uniquely identifies the Agent.

Returns:

  • (String, nil)

    An OpenID URI that uniquely identifies the Agent.



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

def open_id
  @open_id
end

Instance Method Details

#to_hHash{String => String, Hash}

Converts the Agent object into a hash representation suitable for serialization in an xAPI Statement.

Examples:

agent = ActiveLrs::Xapi::Agent.new(
  "name" => "Jane Doe",
  "mbox" => "mailto:[email protected]"
)
agent.to_h
# => {
#   "objectType" => "Agent",
#   "name" => "Jane Doe",
#   "mbox" => "mailto:[email protected]"
# }

Returns:

  • (Hash{String => String, Hash})

    a hash including only the present attributes (objectType, name, mbox, mbox_sha1sum, openid, account)



74
75
76
77
78
79
80
81
82
83
# File 'lib/active_lrs/xapi/agent.rb', line 74

def to_h
  node = {}
  node["objectType"] = object_type
  node["name"] = name if name
  node["mbox"] = mbox if mbox
  node["mbox_sha1sum"] = mbox_sha1_sum if mbox_sha1_sum
  node["openid"] = open_id if open_id
  node["account"] = .to_h if 
  node
end