Sha256: fa78daa885083bd39026b7bfa4b2bde0d4844ce5180e3adbf4ee3a576678cd62

Contents?: true

Size: 935 Bytes

Versions: 2

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

module Rokaki
  module FilterModel
    class LikeKeys
      def initialize(args)
        @args = args
        @like_keys = []
      end

      attr_reader :args, :like_keys

      def call
        args.keys.each do |key|
          like_keys << map_keys(args[key], key)
        end
        like_keys
      end

      private

      def map_keys(value, key)
        key_result = {}

        if value.is_a? Hash
        value.keys.each do |sub_key|
          sub_value = value[sub_key]

          if sub_value.is_a? Symbol
            if key_result[key].is_a? Array
              key_result[key] << sub_key
            else
              key_result[key] = [ sub_key ]
            end

          elsif sub_value.is_a? Hash
            key_result[key] = map_keys(sub_value, sub_key)
          end
        end
        else
          key_result = key
        end

        key_result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rokaki-0.5.1 lib/rokaki/filter_model/like_keys.rb
rokaki-0.5.0 lib/rokaki/filter_model/like_keys.rb