33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/evesync/ipc/data/hashable.rb', line 33
def from_hash(hash)
Log.debug("IPC Data message hash parsing: #{hash}")
params = {}
hash.each do |key, value|
next unless key =~ /^@/
if value.is_a? Hash
begin
cl = Object.const_get value['type']
rescue NameError => e
Log.fatal("IPC Data Unsupported type: #{hash['type']}")
raise e
end
unless cl.respond_to? :from_hash
err_msg = "IPC Data ERROR Class #{cl} must implement `self.from_hash'"
Log.fatal(err_msg)
raise err_msg
end
complex_value = cl.from_hash value
params[key.sub('@', '').to_sym] = complex_value
else
params[key.sub('@', '').to_sym] = value
end
end
begin
cl = Object.const_get hash['type']
rescue TypeError, NameError
cl = self
end
cl.new(params)
end
|