Class: TinCanApi::Context

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

Overview

Context Class Description

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Context.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tin_can_api/context.rb', line 9

def initialize(options={}, &block)
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.registration = attributes['registration'] if attributes['registration']
    self.instructor = TinCanApi::Agent.new(json: attributes['instructor'].to_json) if attributes['instructor']
    self.team = TinCanApi::Agent.new(json: attributes['team'].to_json) if attributes['team']
    self.context_activities = TinCanApi::ContextActivities.new(json: attributes['contextActivities'].to_json) if attributes['contextActivities']
    self.revision = attributes['revision'] if attributes['revision']
    self.platform = attributes['platform'] if attributes['platform']
    self.language = attributes['language'] if attributes['language']
    self.statement = TinCanApi::StatementRef.new(json: attributes['statement'].to_json) if attributes['statement']
    self.extensions = attributes['extensions'] if attributes['extensions']
  else
    self.registration = options.fetch(:registration, nil)
    self.instructor = options.fetch(:instructor, nil)
    self.team = options.fetch(:team, nil)
    self.context_activities = options.fetch(:context_activities, nil)
    self.revision = options.fetch(:revision, nil)
    self.platform = options.fetch(:platform, nil)
    self.language = options.fetch(:language, nil)
    self.extensions = options.fetch(:extensions, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#context_activitiesObject

Returns the value of attribute context_activities.



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

def context_activities
  @context_activities
end

#extensionsObject

Returns the value of attribute extensions.



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

def extensions
  @extensions
end

#instructorObject

Returns the value of attribute instructor.



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

def instructor
  @instructor
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#platformObject

Returns the value of attribute platform.



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

def platform
  @platform
end

#registrationObject

Returns the value of attribute registration.



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

def registration
  @registration
end

#revisionObject

Returns the value of attribute revision.



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

def revision
  @revision
end

#statementObject

Returns the value of attribute statement.



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

def statement
  @statement
end

#teamObject

Returns the value of attribute team.



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

def team
  @team
end

Instance Method Details

#serialize(version) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tin_can_api/context.rb', line 38

def serialize(version)
  node = {}
  node['registration'] = registration if registration
  node['instructor'] = instructor.serialize(version) if instructor
  node['team'] = team.serialize(version) if team
  node['contextActivities'] = context_activities.serialize(version) if context_activities
  node['revision'] = revision if revision
  node['platform'] = platform if platform
  node['language'] = language if language
  node['statement'] = statement.serialize(version) if statement
  node['extensions'] = extensions if extensions

  node
end