Class: TinCanApi::InteractionComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/tin_can_api/interaction_component.rb

Overview

InteractionComponent Class Description

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ InteractionComponent

Returns a new instance of InteractionComponent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tin_can_api/interaction_component.rb', line 8

def initialize(options={}, &block)
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.id = attributes['id'] if attributes['id']
    self.description = attributes['description'] if attributes['description']
  else
    self.id = options.fetch(:id, nil)
    self.description = options.fetch(:description, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/tin_can_api/interaction_component.rb', line 6

def description
  @description
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/tin_can_api/interaction_component.rb', line 6

def id
  @id
end

Instance Method Details

#serialize(version) ⇒ Object



24
25
26
27
28
29
# File 'lib/tin_can_api/interaction_component.rb', line 24

def serialize(version)
  node = {}
  node['id'] = id if id
  node['description'] = description if description
  node
end