lib/rbCFPropertyList.rb in CFPropertyList-2.0.10 vs lib/rbCFPropertyList.rb in CFPropertyList-2.0.11

- old
+ new

@@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- require 'libxml' require 'kconv' require 'date' +require 'time' # # CFPropertyList implementation # # class to read, manipulate and write both XML and binary property list @@ -55,27 +56,39 @@ return true end end end -dirname = File.dirname(__FILE__) -require dirname + '/rbCFPlistError.rb' -require dirname + '/rbCFTypes.rb' -require dirname + '/rbXMLCFPropertyList.rb' -require dirname + '/rbBinaryCFPropertyList.rb' +class String + unless("".respond_to?(:blob) && "".respond_to?(:blob=)) then + # The blob status of this string (to set to true if a binary string) + attr_accessor :blob + end -require 'iconv' unless "".respond_to?("encode") + unless("".respond_to?(:blob?)) then + # Returns whether or not +str+ is a blob. + # @return [true,false] If true, this string contains binary data. If false, its a regular string + def blob? + @blob + end + end -class String unless("".respond_to?(:bytesize)) then def bytesize self.length end end end +dirname = File.dirname(__FILE__) +require dirname + '/rbCFPlistError.rb' +require dirname + '/rbCFTypes.rb' +require dirname + '/rbXMLCFPropertyList.rb' +require dirname + '/rbBinaryCFPropertyList.rb' +require 'iconv' unless "".respond_to?("encode") + module CFPropertyList # Create CFType hierarchy by guessing the correct CFType, e.g. # # x = { # 'a' => ['b','c','d'] @@ -93,14 +106,14 @@ elsif(object.is_a?(Float) || (Object.const_defined?('BigDecimal') and object.is_a?(BigDecimal))) then return CFReal.new(object) elsif(object.is_a?(TrueClass) || object.is_a?(FalseClass)) then return CFBoolean.new(object) elsif(object.is_a?(String)) then - return CFString.new(object) + return object.blob? ? CFData.new(object, CFData::DATA_RAW) : CFString.new(object) + elsif(object.is_a?(IO)) then + return CFData.new(object.read(), CFData::DATA_RAW) elsif(object.is_a?(Time) || object.is_a?(DateTime) || object.is_a?(Date)) then return CFDate.new(object) - elsif(object.is_a?(IO)) then - return CFData.new(object.read, CFData::DATA_RAW) elsif(object.is_a?(Array)) then ary = Array.new object.each do |o| ary.push CFPropertyList.guess(o, options)