Sha256: 5b8787b477846ad6a418c190cc8260a2c093d6f35e53c31e96df6f0d5d54ddb2

Contents?: true

Size: 632 Bytes

Versions: 8

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

require_relative "binary_operator"

class InOperator
  include BinaryOperator

  def binary(evaluator, haystack, needle)
    if haystack.is_a? Array
      haystack.each do |item|
        return true if evaluator.compare(item, needle) == 0
      end
      return false
    elsif haystack.is_a? String
      needle_string = evaluator.string_convert(needle)
      return !needle_string.nil? && haystack.include?(needle_string)
    elsif haystack.is_a?(Hash)
      needle_string = evaluator.string_convert(needle)
      return !needle_string.nil? && haystack.key?(needle_string)
    end
    nil
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
absmartly-sdk-1.1.2 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.1.1 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.1.0 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.0.8 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.0.7 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.0.6 lib/json_expr/operators/in_operator.rb
absmartly-sdk-1.0.5 lib/json_expr/operators/in_operator.rb
absmartly-sdk-0.1.2 lib/json_expr/operators/in_operator.rb