added 2.0.4 CFPropertyList
This commit is contained in:
parent
4abce3b7ec
commit
14ae6ff27f
2 changed files with 27 additions and 3 deletions
19
lib/cfpropertylist/rbCFPlistError.rb
Normal file
19
lib/cfpropertylist/rbCFPlistError.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# CFFormatError implementation
|
||||||
|
#
|
||||||
|
# Author:: Christian Kruse (mailto:cjk@wwwtech.de)
|
||||||
|
# Copyright:: Copyright (c) 2010
|
||||||
|
# License:: MIT License
|
||||||
|
|
||||||
|
class CFPlistError < Exception
|
||||||
|
end
|
||||||
|
|
||||||
|
# Exception thrown when format errors occur
|
||||||
|
class CFFormatError < CFPlistError
|
||||||
|
end
|
||||||
|
|
||||||
|
class CFTypeError < CFPlistError
|
||||||
|
end
|
||||||
|
|
||||||
|
# eof
|
|
@ -55,7 +55,7 @@ module CFPropertyList
|
||||||
end
|
end
|
||||||
|
|
||||||
dirname = File.dirname(__FILE__)
|
dirname = File.dirname(__FILE__)
|
||||||
require dirname + '/rbCFFormatError.rb'
|
require dirname + '/rbCFPlistError.rb'
|
||||||
require dirname + '/rbCFTypes.rb'
|
require dirname + '/rbCFTypes.rb'
|
||||||
require dirname + '/rbXMLCFPropertyList.rb'
|
require dirname + '/rbXMLCFPropertyList.rb'
|
||||||
require dirname + '/rbBinaryCFPropertyList.rb'
|
require dirname + '/rbBinaryCFPropertyList.rb'
|
||||||
|
@ -69,9 +69,12 @@ module CFPropertyList
|
||||||
# 'a' => ['b','c','d']
|
# 'a' => ['b','c','d']
|
||||||
# }
|
# }
|
||||||
# cftypes = CFPropertyList.guess(x)
|
# cftypes = CFPropertyList.guess(x)
|
||||||
|
#
|
||||||
|
# pass optional options hash. Only possible value actually:
|
||||||
|
# :convert_unknown_to_string => true
|
||||||
|
#
|
||||||
|
# cftypes = CFPropertyList.guess(x,:convert_unknown_to_string => true)
|
||||||
def guess(object, options = {})
|
def guess(object, options = {})
|
||||||
return if object.nil?
|
|
||||||
|
|
||||||
if(object.is_a?(Fixnum) || object.is_a?(Integer)) then
|
if(object.is_a?(Fixnum) || object.is_a?(Integer)) then
|
||||||
return CFInteger.new(object)
|
return CFInteger.new(object)
|
||||||
elsif(object.is_a?(Float)) then
|
elsif(object.is_a?(Float)) then
|
||||||
|
@ -103,6 +106,8 @@ module CFPropertyList
|
||||||
return CFDictionary.new(hsh)
|
return CFDictionary.new(hsh)
|
||||||
elsif options[:convert_unknown_to_string]
|
elsif options[:convert_unknown_to_string]
|
||||||
return CFString.new(object.to_s)
|
return 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
|
end
|
||||||
|
|
||||||
|
|
Reference in a new issue