Module: HelpScout::Util

Defined in:
lib/help_scout/util.rb

Class Method Summary collapse

Class Method Details

.camelize(term) ⇒ Object



7
8
9
10
11
# File 'lib/help_scout/util.rb', line 7

def camelize(term)
  term = term.to_s.split('_').collect(&:capitalize).join
  term[0] = term[0].downcase
  term
end

.camelize_keys(source) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/help_scout/util.rb', line 13

def camelize_keys(source)
  source.each_with_object({}) do |(key, value), results|
    results[camelize(key)] = if value.is_a? Hash
                               camelize_keys(value)
                             else
                               value
                             end
  end
end

.jsonify(term) ⇒ Object



23
24
25
# File 'lib/help_scout/util.rb', line 23

def jsonify(term)
  camelize(keyify(term))
end

.keyify(term) ⇒ Object



27
28
29
# File 'lib/help_scout/util.rb', line 27

def keyify(term)
  term.to_s.delete('@')
end


31
32
33
# File 'lib/help_scout/util.rb', line 31

def map_links(links)
  links.map { |k, v| [k, v[:href]] }.to_h
end

.parse_path(path_template, replacements) ⇒ Object



35
36
37
38
# File 'lib/help_scout/util.rb', line 35

def parse_path(path_template, replacements)
  placeholders = Regexp.union(replacements.keys)
  path_template.gsub(placeholders) { |match_text| replacements[match_text] }
end

.serialized_value(value, type) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/help_scout/util.rb', line 40

def serialized_value(value, type)
  if value.is_a? Array
    value.map { |v| serialized_value(v, type) }
  else
    value.class < HelpScout::Base ? value.send(type) : value
  end
end