Module: Elasticated::Helpers

Defined in:
lib/elasticated/helpers.rb

Class Method Summary collapse

Class Method Details

.hash_deep_dup(hash) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/elasticated/helpers.rb', line 13

def self.hash_deep_dup(hash)
  duplicate = hash.dup
  duplicate.each_pair do |k, v|
    if v.is_a? Hash
      duplicate[k] = hash_deep_dup v
    elsif v.is_a? Array
      duplicate[k] = v.clone
    else
      duplicate[k] = v
    end
  end
  duplicate
end

.string_to_agg_name(element) ⇒ Object



4
5
6
# File 'lib/elasticated/helpers.rb', line 4

def self.string_to_agg_name(element)
  element.to_s.gsub /(?![a-zA-Z0-9])./, '_'
end

.string_to_camel_case(string) ⇒ Object



8
9
10
11
# File 'lib/elasticated/helpers.rb', line 8

def self.string_to_camel_case(string)
  return string if string !~ /_/ && string =~ /[A-Z]+.*/
  string.split('_').map(&:capitalize).join
end