Method: UI2API::Base#convert_to_model

Defined in:
lib/ui2api.rb

#convert_to_model(data) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ui2api.rb', line 105

def convert_to_model(data)
  if data.is_a? Hash
    return if (model_object.valid_keys & data.keys).empty?
    begin
      model_object.convert(data)
    rescue StandardError => ex
      raise unless ex.message.include?('Can not convert Hash to Model')
    end
  elsif data.is_a? Array
    data.map do |hash|
      model = convert_to_model(hash)
      model.nil? ? return : model
    end
  end
end