Module: Idnow::Jsonable

Included in:
ContactData, DocumentDefinition, Identification, IdentificationDocument, IdentificationProcess, UserData
Defined in:
lib/idnow/modules/jsonable.rb

Instance Method Summary collapse

Instance Method Details

#to_hObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/idnow/modules/jsonable.rb', line 3

def to_h
  instance_variables.each_with_object({}) do |var, result_hash|
    key = var.to_s.delete('@')
    value = if instance_variable_get(var).respond_to?(:to_h)
              instance_variable_get(var).to_h
            else
              instance_variable_get(var).to_s
            end
    result_hash[key] = value
  end
end

#to_jsonObject



15
16
17
# File 'lib/idnow/modules/jsonable.rb', line 15

def to_json
  keys_without_underscores(to_h).to_json
end