Module: Zm::Client::Utils

Defined in:
lib/zm/client/common/utils.rb

Constant Summary collapse

A_ARRAY_PROC =
->(i) { i.last.is_a?(Array) ? i.last.map { |j| [i.first, j] } : [i] }
A_NODE_PROC =
->(n) { { n: n.first, _content: n.last } }
ARROW =
'@'
EQUALS =
'='

Class Method Summary collapse

Class Method Details

.arrow_name(name) ⇒ Object

TODO: chercher - remplacer toutes les occurences dans le code



31
32
33
34
35
# File 'lib/zm/client/common/utils.rb', line 31

def arrow_name(name)
  return name if name.to_s.start_with?(ARROW)

  "#{ARROW}#{name}"
end

.arrow_name_sym(name) ⇒ Object



37
38
39
# File 'lib/zm/client/common/utils.rb', line 37

def arrow_name_sym(name)
  arrow_name(name).to_sym
end

.equals_name(name) ⇒ Object



41
42
43
44
45
# File 'lib/zm/client/common/utils.rb', line 41

def equals_name(name)
  return name if name.to_s.end_with?(EQUALS)

  "#{name}#{EQUALS}"
end

.format_email(email) ⇒ Object



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

def format_email(email)
  email.strip!
  email.downcase!
  email
end

.format_url_params(hash) ⇒ Object



24
25
26
27
28
# File 'lib/zm/client/common/utils.rb', line 24

def format_url_params(hash)
  uri = Addressable::URI.new
  uri.query_values = hash
  uri.query
end

.format_url_path(path) ⇒ Object



20
21
22
# File 'lib/zm/client/common/utils.rb', line 20

def format_url_path(path)
  Addressable::URI.escape path
end

.map_format(array, klass, method_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zm/client/common/utils.rb', line 47

def map_format(array, klass, method_name)
  array.map! do |item|
    if item.is_a?(klass)
      item
    elsif item.respond_to?(method_name)
      item.name
    end
  end
  array.compact!
  array
end