Class: Zm::Client::ContactJsnsInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/contact/contact_jsns_initializer.rb

Overview

class for account contact

Class Method Summary collapse

Class Method Details

.create(parent, json) ⇒ Object



8
9
10
11
# File 'lib/zm/client/contact/contact_jsns_initializer.rb', line 8

def create(parent, json)
  item = Contact.new(parent)
  update(item, json)
end

.init_by_attrs(attrs, item) ⇒ Object



63
64
65
66
67
68
# File 'lib/zm/client/contact/contact_jsns_initializer.rb', line 63

def init_by_attrs(attrs, item)
  attrs.each do |k, v|
    m = Utils.equals_name(k)
    item.send(m, v) if item.respond_to?(m)
  end
end

.init_members_from_json(m, item) ⇒ Object



70
71
72
73
74
# File 'lib/zm/client/contact/contact_jsns_initializer.rb', line 70

def init_members_from_json(m, item)
  return if m.nil?

  item.members.all = m.map { |m| Zm::Client::ConcatMember.new(m[:type], m[:value]) }
end

.make_custom_keys(attrs, item) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/zm/client/contact/contact_jsns_initializer.rb', line 54

def make_custom_keys(attrs, item)
  custom_keys = attrs.keys - item.all_instance_variable_keys
  return if custom_keys.empty?

  item.class.attr_accessor(*custom_keys)
rescue StandardError => _e
  nil
end

.update(item, json) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zm/client/contact/contact_jsns_initializer.rb', line 13

def update(item, json)
  part_id = json[:id].split(':')

  if part_id.length == 1
    item.id = json[:id].to_i
  elsif part_id.length == 2
    item. = part_id.first
    item.id = part_id.last.to_i
  else
    item.id = json[:id]
  end

  part_l = json[:l].split(':')

  if part_l.length == 1
    item.l = json[:l].to_i
  elsif part_l.length == 2
    item. = part_l.first
    item.l = part_l.last.to_i
  else
    item.l = json[:l]
  end

  # item.id   = json[:id]
  item.name = json[:fileAsStr]
  # item.l    = json[:l].to_i
  item.tn   = json[:tn]

  if json[:_attrs].is_a?(Hash)
    make_custom_keys(json[:_attrs], item)
    init_by_attrs(json[:_attrs], item)
  end

  if item.group?
    item.extend(GroupContact)
    init_members_from_json(json[:m], item)
  end

  item
end