Class: ActiveLrs::Xapi::Attachment
- Inherits:
-
Object
- Object
- ActiveLrs::Xapi::Attachment
- Includes:
- LocalizationHelper
- Defined in:
- lib/active_lrs/xapi/attachment.rb
Overview
Represents an xAPI Attachment object.
Attachments provide additional context or supporting data for an xAPI Statement, such as documents, media files, or extensions. Each Attachment includes metadata such as usage type, display name, content type, length, and a SHA-2 hash for validation.
This class is intended for use in the attachments property of an xAPI Statement.
Instance Attribute Summary collapse
-
#content_type ⇒ String?
The MIME type of the Attachment (e.g., “image/png”).
-
#description ⇒ Hash{String => String}?
A language map providing a human-readable description of the Attachment.
-
#display ⇒ Hash{String => String}?
A language map providing a display name for the Attachment.
-
#file_url ⇒ String?
An IRL (Internationalized Resource Locator) pointing to the Attachment file.
-
#length ⇒ Integer?
The size of the Attachment file in bytes.
-
#sha2 ⇒ String?
The SHA-2 hash of the Attachment data, used for integrity checks.
-
#usage_type ⇒ String?
An IRI indicating the intended use of this Attachment (e.g., “id.tincanapi.com/attachment/supporting_media”).
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ void
constructor
Initializes a new Attachment instance with optional attributes.
-
#localize_description(locale: nil) ⇒ String
Returns the localized description of the attachment.
-
#localize_display(locale: nil) ⇒ String
Returns the localized display of the attachment.
-
#to_h ⇒ Hash{String => String, Hash, Integer}
Converts the Attachment object into a hash representation suitable for serialization in an xAPI Statement.
Methods included from LocalizationHelper
Constructor Details
#initialize(attributes = {}) ⇒ void
Initializes a new Attachment instance with optional attributes.
56 57 58 59 60 61 62 63 64 |
# File 'lib/active_lrs/xapi/attachment.rb', line 56 def initialize(attributes = {}) self.usage_type = attributes["usageType"] if attributes["usageType"] self.display = attributes["display"] if attributes["display"] self.description = attributes["description"] if attributes["description"] self.content_type = attributes["contentType"] if attributes["contentType"] self.length = attributes["length"] if attributes["length"] self.sha2 = attributes["sha2"] if attributes["sha2"] self.file_url = attributes["fileUrl"] if attributes["fileUrl"] end |
Instance Attribute Details
#content_type ⇒ String?
Returns The MIME type of the Attachment (e.g., “image/png”).
32 33 34 |
# File 'lib/active_lrs/xapi/attachment.rb', line 32 def content_type @content_type end |
#description ⇒ Hash{String => String}?
Returns A language map providing a human-readable description of the Attachment.
29 30 31 |
# File 'lib/active_lrs/xapi/attachment.rb', line 29 def description @description end |
#display ⇒ Hash{String => String}?
Returns A language map providing a display name for the Attachment.
25 26 27 |
# File 'lib/active_lrs/xapi/attachment.rb', line 25 def display @display end |
#file_url ⇒ String?
Returns An IRL (Internationalized Resource Locator) pointing to the Attachment file.
42 43 44 |
# File 'lib/active_lrs/xapi/attachment.rb', line 42 def file_url @file_url end |
#length ⇒ Integer?
Returns The size of the Attachment file in bytes.
35 36 37 |
# File 'lib/active_lrs/xapi/attachment.rb', line 35 def length @length end |
#sha2 ⇒ String?
Returns The SHA-2 hash of the Attachment data, used for integrity checks.
38 39 40 |
# File 'lib/active_lrs/xapi/attachment.rb', line 38 def sha2 @sha2 end |
#usage_type ⇒ String?
Returns An IRI indicating the intended use of this Attachment (e.g., “id.tincanapi.com/attachment/supporting_media”).
21 22 23 |
# File 'lib/active_lrs/xapi/attachment.rb', line 21 def usage_type @usage_type end |
Instance Method Details
#localize_description(locale: nil) ⇒ String
Returns the localized description of the attachment.
114 115 116 |
# File 'lib/active_lrs/xapi/attachment.rb', line 114 def localize_description(locale: nil) get_localized_value(description, locale) end |
#localize_display(locale: nil) ⇒ String
Returns the localized display of the attachment.
106 107 108 |
# File 'lib/active_lrs/xapi/attachment.rb', line 106 def localize_display(locale: nil) get_localized_value(display, locale) end |
#to_h ⇒ Hash{String => String, Hash, Integer}
Converts the Attachment object into a hash representation suitable for serialization in an xAPI Statement.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/active_lrs/xapi/attachment.rb', line 90 def to_h node = {} node["usageType"] = usage_type if usage_type node["display"] = display if display node["description"] = description if description node["contentType"] = content_type if content_type node["length"] = length if length node["sha2"] = sha2 if sha2 node["fileUrl"] = file_url if file_url node end |