Sha256: 26ab42b212242667ec7500f63a4cb6ecd18f7d49b98a96b494cbe0e3ec32681f

Contents?: true

Size: 728 Bytes

Versions: 8

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module BingAdsRubySdk
  module Postprocessors
    class Snakize

      def initialize(params)
        @params = params
      end

      def call
        process(@params)
      end

      private

      # NOTE: there is a potential for high memory usage here as we're using recursive method calling
      def process(obj)
        return obj unless obj.is_a?(Hash)

        obj.each_with_object({}) do |(k, v), h|
          case v
          when Hash then v = process(v)
          when Array then v = v.map {|elt| process(elt) }
          end
          h[snakize(k)] = v
        end
      end

      def snakize(string)
        BingAdsRubySdk::StringUtils.snakize(string)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.3.4 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.3.3 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.3.2 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.3.1 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.3.0 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.2.0 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.1.1 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb
bing_ads_ruby_sdk-1.0.0 lib/bing_ads_ruby_sdk/postprocessors/snakize.rb