def guess(object, options = {})
case object
when Integer then CFInteger.new(object)
when UidFixnum then CFUid.new(object)
when Float then CFReal.new(object)
when TrueClass, FalseClass then CFBoolean.new(object)
when Blob
CFData.new(object, CFData::DATA_RAW)
when String, Symbol
CFString.new(object.to_s)
when Time, DateTime, Date
CFDate.new(object)
when Array, Enumerator
ary = Array.new
object.each do |o|
ary.push CFPropertyList.guess(o, options)
end
CFArray.new(ary)
when Hash
hsh = Hash.new
object.each_pair do |k,v|
k = k.to_s if k.is_a?(Symbol)
hsh[k] = CFPropertyList.guess(v, options)
end
CFDictionary.new(hsh)
else
case
when Object.const_defined?('BigDecimal') && object.is_a?(BigDecimal)
CFReal.new(object)
when object.respond_to?(:read)
raw_data = object.read
raw_data.force_encoding(Encoding::ASCII_8BIT) if raw_data.respond_to?(:force_encoding)
CFData.new(raw_data, CFData::DATA_RAW)
when options[:converter_method] && object.respond_to?(options[:converter_method])
if options[:converter_with_opts]
CFPropertyList.guess(object.send(options[:converter_method],options),options)
else
CFPropertyList.guess(object.send(options[:converter_method]),options)
end
when options[:convert_unknown_to_string]
CFString.new(object.to_s)
else
raise CFTypeError.new("Unknown class #{object.class.to_s}. Try using :convert_unknown_to_string if you want to use unknown object types!")
end
end
end