Module: Chartkick::Utils

Defined in:
lib/chartkick/utils.rb

Constant Summary collapse

JSON_ESCAPE =
{ "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
JSON_ESCAPE_REGEXP =
/[\u2028\u2029&><]/u

Class Method Summary collapse

Class Method Details

.deep_merge(hash_a, hash_b) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/chartkick/utils.rb', line 4

def self.deep_merge(hash_a, hash_b)
  hash_a = hash_a.dup
  hash_b.each_pair do |k, v|
    tv = hash_a[k]
    hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge(tv, v) : v
  end
  hash_a
end

.json_escape(s) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/chartkick/utils.rb', line 16

def self.json_escape(s)
  if ERB::Util.respond_to?(:json_escape)
    ERB::Util.json_escape(s)
  else
    s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
  end
end