# File lib/puppet/type.rb, line 1031
1031:     def self.hash2resource(hash)
1032:         hash = hash.inject({}) { |result, ary| result[ary[0].to_sym] = ary[1]; result }
1033: 
1034:         if title = hash[:title]
1035:             hash.delete(:title)
1036:         else
1037:             if self.namevar != :name
1038:                 if hash.include?(:name) and hash.include?(self.namevar)
1039:                     raise Puppet::Error, "Cannot provide both name and %s to resources of type %s" % [self.namevar, self.name]
1040:                 end
1041:                 if title = hash[self.namevar]
1042:                     hash.delete(self.namevar)
1043:                 end
1044:             end
1045: 
1046:             unless title ||= hash[:name]
1047:                 raise Puppet::Error, "You must specify a name or title for resources"
1048:             end
1049:         end
1050: 
1051: 
1052:         # Now create our resource.
1053:         resource = Puppet::Resource.new(self.name, title)
1054:         [:catalog].each do |attribute|
1055:             if value = hash[attribute]
1056:                 hash.delete(attribute)
1057:                 resource.send(attribute.to_s + "=", value)
1058:             end
1059:         end
1060: 
1061:         hash.each do |param, value|
1062:             resource[param] = value
1063:         end
1064:         return resource
1065:     end