98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/api_object.rb', line 98
def initialize(*args)
url = args.first.delete(:url)
errors = args.first.delete(:errors)
tags = respond_to?('data_tags') ? self.data_tags : args.last[:tags]
args.first.each do |k, v|
k = k.gsub(/@/, '')
k = self.columns[k.to_sym] unless self.columns[k.to_sym].nil?
if self.respond_to?(k) klass = self.assoc[k.to_sym] || k
result = v.instance_of?(Array) ? v.map {|v1| init_object(v1, klass, tags)} : init_object(v, klass, tags)
instance_variable_set("@#{k.to_s}", result)
end
end if args.first.is_a?(Hash)
if self.empty?
puts "ERROR: data passed for #{self.class} initialization was invalid. #{self.class.error_invalid_url url}"
@errors = errors || self.class.invalid_data_msg
end
end
|