Class: ActiveLrs::Xapi::Verb

Inherits:
Object
  • Object
show all
Includes:
LocalizationHelper
Defined in:
lib/active_lrs/xapi/verb.rb

Overview

Represents an xAPI Verb object.

A Verb describes the action that the Actor performed on the Object. Each Verb must have an id (IRI) and may optionally include a human-readable display map of language codes to strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LocalizationHelper

#get_localized_value

Constructor Details

#initialize(attributes = {}) ⇒ void

Initializes a new Verb object.

Parameters:

  • (defaults to: {})

    Attributes for the Verb

Options Hash (attributes):

  • "id" (String)

    Required IRI of the verb

  • "display" (Hash{String => String})

    Optional human-readable display map



31
32
33
34
35
36
37
38
39
# File 'lib/active_lrs/xapi/verb.rb', line 31

def initialize(attributes = {})
  self.id = attributes["id"] if attributes["id"]

  if attributes["display"]
    self.display = attributes["display"]
    locale = ActiveLrs.configuration.default_locale
    self.name = attributes["display"][locale] || attributes["display"].values.first
  end
end

Instance Attribute Details

#displayHash{String => String}?

Returns Optional map of language codes to human-readable representations.

Returns:

  • Optional map of language codes to human-readable representations



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

def display
  @display
end

#idString

Returns IRI that uniquely identifies the verb.

Returns:

  • IRI that uniquely identifies the verb



16
17
18
# File 'lib/active_lrs/xapi/verb.rb', line 16

def id
  @id
end

#nameString?

Returns Optional human-readable verb string for a chosen locale (defaults to first available).

Returns:

  • Optional human-readable verb string for a chosen locale (defaults to first available)



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

def name
  @name
end

Instance Method Details

#localize_display(locale: nil) ⇒ String

Returns the localized display of the verb.

Parameters:

  • (defaults to: nil)

    Optional locale to use. Defaults to nil (will use configured defaults).

Returns:

  • The localized display, or “undefined” if not available.



66
67
68
# File 'lib/active_lrs/xapi/verb.rb', line 66

def localize_display(locale: nil)
  get_localized_value(display, locale)
end

#to_hHash{String => Object}

Converts the Verb object into a hash suitable for xAPI Statements.

Examples:

verb = ActiveLrs::Xapi::Verb.new(
  "id" => "http://adlnet.gov/expapi/verbs/completed",
  "display" => { "en-US" => "completed" }
)
verb.to_h
# => {
#   "id" => "http://adlnet.gov/expapi/verbs/completed",
#   "display" => { "en-US" => "completed" }
# }

Returns:

  • Hash representation of the Verb



55
56
57
58
59
60
# File 'lib/active_lrs/xapi/verb.rb', line 55

def to_h
  node = {}
  node["id"] = id.to_s if id
  node["display"] = display if display
  node
end