Sha256: 72c21216dd3b4d961ad656b3b49be0a2276b17cc22ec14480a3db952388423c5

Contents?: true

Size: 559 Bytes

Versions: 5

Compression:

Stored size: 559 Bytes

Contents

# frozen_string_literal: true

require "ostruct"

module Onyphe
  class Response < OpenStruct
    def openstruct_to_hash(object, hash = {})
      return object unless object.respond_to?(:each_pair)

      object.each_pair do |key, value|
        hash[key] = case value
                    when OpenStruct then openstruct_to_hash(value)
                    when Array then value.map { |v| openstruct_to_hash(v) }
                    else value
                    end
      end
      hash
    end

    def to_h
      openstruct_to_hash(self)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
onyphe-0.2.3 lib/onyphe/response.rb
onyphe-0.2.2 lib/onyphe/response.rb
onyphe-0.2.1 lib/onyphe/response.rb
onyphe-0.2.0 lib/onyphe/response.rb
onyphe-0.1.0 lib/onyphe/response.rb