Class: Zimbra::BaseService::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/zimbra/base.rb

Overview

Doc Placeholder

Class Method Summary collapse

Class Method Details

.attributes_names(node) ⇒ Object

This method run over the children of the node and for each one gets the value of the n attribute “<a n="zimbraMailAlias">[email protected]</a>” would be zimbraMailAlias



212
213
214
# File 'lib/zimbra/base.rb', line 212

def attributes_names(node)
  (node/'n2:a').map { |e| (e/'@n').to_s }.uniq
end

.get_all_response(class_name, response) ⇒ Object



191
192
193
194
195
196
# File 'lib/zimbra/base.rb', line 191

def get_all_response(class_name, response)
  namespace = Zimbra::Base::NAMESPACES[class_name]
  (response/"//n2:#{namespace}").map do |node|
    response(class_name, node, false)
  end
end

.get_attributes(node, names = []) ⇒ Object



216
217
218
219
220
221
222
223
# File 'lib/zimbra/base.rb', line 216

def get_attributes(node, names = [])
  attr_hash = {}
  return attr_hash if names.empty?
  names.each do |attr|
    attr_hash[attr] = Zimbra::A.read node, attr
  end
  attr_hash
end

.response(class_name, node, full = true) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'lib/zimbra/base.rb', line 198

def response(class_name, node, full = true)
  object = Object.const_get "Zimbra::#{class_name}"
  names = full ? attributes_names(node) : object.zimbra_attrs_to_load
  attrs = get_attributes(node, names)

  id = (node/'@id').to_s
  name = (node/'@name').to_s
  object.new(id, name, attrs, node)
end