Class: TinCanApi::Activity

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

Overview

Activity model class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Activity.



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

def initialize(options={}, &block)
  @object_type = 'Activity'
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.id =  Addressable::URI.parse(attributes['id']) if attributes['id']
    self.definition = ActivityDefinition.new(json: attributes['definition'].to_json) if attributes['definition']
  else
    self.id = options.fetch(:id, nil)
    self.definition = options.fetch(:definition, nil)
    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#definitionObject

Returns the value of attribute definition.



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

def definition
  @definition
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/tin_can_api/activity.rb', line 7

def id
  @id
end

#object_typeObject

Returns the value of attribute object_type.



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

def object_type
  @object_type
end

Instance Method Details

#serialize(version) ⇒ Object



33
34
35
36
37
38
# File 'lib/tin_can_api/activity.rb', line 33

def serialize(version)
  node = {}
  node['id'] = id.to_s if id
  node['definition'] = definition.serialize(version) if definition
  node
end