Sha256: 909ee91639fca79c563f6bce6d62d7fafe08e6e65c3bceeee015aa4f76747f45

Contents?: true

Size: 790 Bytes

Versions: 2

Compression:

Stored size: 790 Bytes

Contents

module Paysafe
  module Refinements
    module CamelCase
      refine Hash do

        def to_camel_case(data = self)
          case data
          when Array
            data.map { |value| to_camel_case(value) }
          when Hash
            data.map { |key, value| [camel_case_key(key), to_camel_case(value)] }.to_h
          else
            data
          end
        end

        private

        def camel_case_key(key)
          camel_case(key.to_s).to_sym
        end

        def camel_case(string)
          @__memoize_camelcase ||= {}
          return @__memoize_camelcase[string] if @__memoize_camelcase[string]
          @__memoize_camelcase[string] = string.gsub(/(?:_+)([a-z])/) { $1.upcase }
          @__memoize_camelcase[string]
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paysafe-0.16.0 lib/paysafe/refinements/camel_case.rb
paysafe-0.15.0 lib/paysafe/refinements/camel_case.rb