Sha256: 4140cc7c528aff53c8aeb51422a853a0e9fe3101a78891dde34e587866d27f3e

Contents?: true

Size: 506 Bytes

Versions: 3

Compression:

Stored size: 506 Bytes

Contents

module APIMatchers
  module Core
    class FindInJSON
      attr_reader :json

      def initialize(json)
        @json = json
      end

      def find(options={})
        expected_key = options.fetch(:node).to_s

        @json.each do |key, value|
          if key == expected_key
            return value
          end
          if value.is_a? Hash
            return FindInJSON.new(value).find(node: expected_key)
          end
        end
        nil # Don't find anything!
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
api_matchers-0.1.0 lib/api_matchers/core/find_in_json.rb
api_matchers-0.0.2 lib/api_matchers/core/find_in_json.rb
api_matchers-0.0.1 lib/api_matchers/core/find_in_json.rb