Sha256: d068e2a9fed5e805174aaae65ff10819cce455d66474aa0dc04764739df3b763

Contents?: true

Size: 797 Bytes

Versions: 32

Compression:

Stored size: 797 Bytes

Contents

module CopyTunerClient
  module DottedHash
    def to_h(dotted_hash)
      hash = {}
      dotted_hash.to_h.transform_keys(&:to_s).sort.each do |key, value|
        _hash = key.split('.').reverse.inject(value) { |memo, key| { key => memo } }
        hash.deep_merge!(_hash)
      end
      hash
    end

    def conflict_keys(dotted_hash)
      all_keys = dotted_hash.keys.sort
      results = {}

      all_keys.each_with_index do |key, index|
        prefix = "#{key}."
        conflict_keys = ((index + 1)..Float::INFINITY)
          .take_while { |i| all_keys[i]&.start_with?(prefix) }
          .map { |i| all_keys[i] }

        if conflict_keys.present?
          results[key] = conflict_keys
        end
      end

      results
    end

    module_function :to_h, :conflict_keys
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
copy_tuner_client-0.19.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.18.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.17.1 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.16.3 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.16.2 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.16.1 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.16.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.15.1 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.15.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.14.2 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.14.1 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.14.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.6 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.5 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.3 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.2 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.1 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.13.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.12.0 lib/copy_tuner_client/dotted_hash.rb
copy_tuner_client-0.11.0 lib/copy_tuner_client/dotted_hash.rb