Method: Collins::Asset.from_json
- Defined in:
- lib/collins/asset.rb
.from_json(json_hash, bare_asset = false) ⇒ Collins::Asset
Given a Hash deserialized from JSON, convert to an Asset
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/collins/asset.rb', line 52 def from_json json_hash, = false (raise Collins::CollinsError.new("Invalid JSON specified for Asset.from_json")) if (json_hash.nil? || !json_hash.is_a?(Hash)) json = deep_copy_hash json_hash json = if json["data"] then json["data"] else json end if or !json.include?("ASSET") then asset = Collins::Asset.new json else asset = Collins::Asset.new json.delete("ASSET") end asset.send('ipmi='.to_sym, Collins::Ipmi.from_json(json.delete("IPMI"))) asset.send('addresses='.to_sym, Collins::Address.from_json(json.delete("ADDRESSES"))) asset.send('power='.to_sym, Collins::Power.from_json(json.delete("POWER"))) asset.send('location=', json.delete("LOCATION")) asset.send('extras=', json) asset end |