Class: ActiveLrs::Xapi::Verb
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::Verb
- 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
-
#display ⇒ Hash{String => String}?
Optional map of language codes to human-readable representations.
-
#id ⇒ String
IRI that uniquely identifies the verb.
-
#name ⇒ String?
Optional human-readable verb string for a chosen locale (defaults to first available).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new Verb object.
-
#localize_display(locale: nil) ⇒ String
Returns the localized display of the verb.
-
#to_h ⇒ Hash{String => Object}
Converts the Verb object into a hash suitable for xAPI Statements.
Methods included from LocalizationHelper
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new Verb object.
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
#display ⇒ Hash{String => String}?
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 |
#id ⇒ String
Returns IRI that uniquely identifies the verb.
16 17 18 |
# File 'lib/active_lrs/xapi/verb.rb', line 16 def id @id end |
#name ⇒ String?
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.
66 67 68 |
# File 'lib/active_lrs/xapi/verb.rb', line 66 def localize_display(locale: nil) get_localized_value(display, locale) end |
#to_h ⇒ Hash{String => Object}
Converts the Verb object into a hash suitable for xAPI Statements.
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 |