Class: IMS::LTI::Models::ContentItems::ContentItem

Inherits:
LTIModel
  • Object
show all
Defined in:
lib/ims/lti/models/content_items/content_item.rb

Direct Known Subclasses

FileItem, LtiLinkItem

Constant Summary collapse

TYPE =
"ContentItem"

Constants inherited from LTIModel

LTIModel::LTI_VERSION_2P0, LTIModel::LTI_VERSION_2P1

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LTIModel

add_attribute, add_attributes, #as_json, #attributes, #attributes=, #from_json, inherit_attributes, inherited, #method_missing, #to_json

Constructor Details

#initialize(attributes = {}) ⇒ ContentItem

Returns a new instance of ContentItem.



14
15
16
17
# File 'lib/ims/lti/models/content_items/content_item.rb', line 14

def initialize(attributes = {})
  super(attributes)
  self.type = TYPE
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class IMS::LTI::Models::LTIModel

Class Method Details

.from_json(json) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ims/lti/models/content_items/content_item.rb', line 19

def self.from_json(json)
  data = json.is_a?(String) ? JSON.parse(json) : json
  case data['@type']
  when 'FileItem'
    FileItem.new.from_json(data)
  when 'LtiLinkItem', 'LtiLink'
    LtiLinkItem.new.from_json(data)
  else
    ContentItem.new.from_json(data)
  end
end