Class: TinCanApi::Group

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

Overview

Group model class

Instance Attribute Summary collapse

Attributes inherited from Agent

#account, #mbox, #mbox_sha1_sum, #name, #object_type, #open_id

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Group.



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

def initialize(options={}, &block)
  super(options, &block)

  @object_type = 'Group'
  @members = []
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    attributes['member'].each do |member|
      members << Agent.new(json: member.to_json)
    end
  else
    self.members = options.fetch(:members, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#membersObject

Returns the value of attribute members.



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

def members
  @members
end

Instance Method Details

#serialize(version) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/tin_can_api/group.rb', line 28

def serialize(version)
  node = super(version)
  if members.any?
    node['member'] = members.map {|member| member.serialize(version)}
  end
  node
end