Sha256: d7e5606c188c76161945236c68c06ba818c8327f4e5498ee4ebf90c5199fb76b

Contents?: true

Size: 641 Bytes

Versions: 1

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

module NumverifyClient
  class Result
    def initialize(data = {})
      convert_to_obj(data)
    end

    def attributes
      instance_variables.each_with_object({}) do |instance_variable, h|
        h[instance_variable[1..instance_variable.length]] = instance_variable_get(instance_variable)
      end
    end

    def to_json
      attributes.to_json
    end

    private

    def convert_to_obj(hash)
      hash.each do |key, value|
        self.class.send(:attr_accessor, key)
        instance_variable_set("@#{key}", value)
        convert_to_obj(value) if value.is_a? Hash
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
numverify-0.3.2 lib/numverify/result.rb