Sha256: 3b896108abc887afa8cf005f7dcf29bbdac65c5036da722ea01d170419b449c0

Contents?: true

Size: 720 Bytes

Versions: 14

Compression:

Stored size: 720 Bytes

Contents

module Utilities
  # Traverse each key, value of the hash and any nested hashes (including those in arrays)
  # E.G. to deep transfrom do:
  #   deep_traverse_hash(obj) { |hash, k, v| hash[k] = v.upcase if v.is_a?(String) }
  def self.deep_traverse_hash(obj, &block)
    if obj.is_a? Array
      obj.each { |val| deep_traverse_hash(val, &block) }
    elsif obj.is_a?(Hash)
      obj.each_pair do |k,v|
        deep_traverse_hash(v, &block)
        block.call(obj, k, v)
      end
    end
  end

  def self.remove_enclosing_quotes(str)
    quote_chars = ['"', '\'']
    quote_chars.each do |quote_char|
      return str[1..-2] if str.start_with?(quote_char) && str.end_with?(quote_char)
    end
    return str
  end 
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cqm-parsers-4.1.1.0 lib/util/util.rb
cqm-parsers-4.1.0.2 lib/util/util.rb
cqm-parsers-4.1.0.1 lib/util/util.rb
cqm-parsers-4.1.0.0 lib/util/util.rb
cqm-parsers-4.0.0.1 lib/util/util.rb
cqm-parsers-3.2.0.2 lib/util/util.rb
cqm-parsers-4.0.0.0 lib/util/util.rb
cqm-parsers-3.2.0.1 lib/util/util.rb
cqm-parsers-3.2.0.0 lib/util/util.rb
cqm-parsers-3.1.1.0 lib/util/util.rb
cqm-parsers-3.1.0.0 lib/util/util.rb
cqm-parsers-3.0.0.0 lib/util/util.rb
cqm-parsers-2.0.1 lib/util/util.rb
cqm-parsers-2.0.0 lib/util/util.rb