Class: Zm::Client::FoldersBuilder

Inherits:
Base::ObjectsBuilder show all
Defined in:
lib/zm/client/folder/folders_builder.rb

Overview

class factory [folders]

Instance Method Summary collapse

Constructor Details

#initialize(parent, json) ⇒ FoldersBuilder

Returns a new instance of FoldersBuilder.



7
8
9
10
11
12
# File 'lib/zm/client/folder/folders_builder.rb', line 7

def initialize(parent, json)
  super(parent, json)
  @key = :folder
  @root_folder = nil
  @list = []
end

Instance Method Details

#construct_tree(parent_folder, json_folders) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/zm/client/folder/folders_builder.rb', line 37

def construct_tree(parent_folder, json_folders)
  json_folders.each do |json_folder|
    folder = FolderJsnsInitializer.create(@parent, json_folder)
    parent_folder.folders << folder

    construct_tree(folder, json_folder[@key]) if !json_folder[@key].nil? && json_folder[@key].any?
  end
end

#construct_tree_ids(json_folders) ⇒ Object



20
21
22
23
24
25
# File 'lib/zm/client/folder/folders_builder.rb', line 20

def construct_tree_ids(json_folders)
  json_folders.each do |json_folder|
    @list << json_folder[:id]
    construct_tree_ids(json_folder[@key]) if !json_folder[@key].nil? && json_folder[@key].any?
  end
end

#flatten(folder = @root_folder, collector = []) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/zm/client/folder/folders_builder.rb', line 46

def flatten(folder = @root_folder, collector = [])
  collector.push(folder)
  folder.folders.each do |child|
    flatten(child, collector)
  end
  collector
end

#idsObject



14
15
16
17
18
# File 'lib/zm/client/folder/folders_builder.rb', line 14

def ids
  root = @json[:GetFolderResponse][@key]
  construct_tree_ids(root.first[@key])
  @list
end

#makeObject



27
28
29
30
31
32
33
34
35
# File 'lib/zm/client/folder/folders_builder.rb', line 27

def make
  root = @json[:GetFolderResponse][@key]

  @root_folder = FolderJsnsInitializer.create(@parent, root.first)

  construct_tree(@root_folder, root.first[@key]) if !root.first[@key].nil? && root.first[@key].any?

  @root_folder
end