Sha256: d82eb475d2bd295806a1aba806bf7430c0662e2c8a427f5d71da53ca1550c175

Contents?: true

Size: 914 Bytes

Versions: 8

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

module BingAdsRubySdk
  module Preprocessors
    class Camelize

      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[transform_key(k.to_s)] = v
        end
      end

      def transform_key(key)
        if BLACKLIST.include?(key)
          key
        else
          camelize(key)
        end
      end

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

      BLACKLIST = %w(long string)
    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/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.3.3 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.3.2 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.3.1 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.3.0 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.2.0 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.1.1 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb
bing_ads_ruby_sdk-1.0.0 lib/bing_ads_ruby_sdk/preprocessors/camelize.rb