Module: Plist4r::Backend::CFPropertyList

Defined in:
lib/plist4r/backend/c_f_property_list.rb

Overview

Source: github.com/ckruse/CFPropertyList

C.Kruse’s CFPropertyList is an independant Ruby Library and written natively in Ruby. Supports binary and xml format property lists. With a dependency on libxml-ruby for reading/writing the xml plists.

Class Method Summary collapse

Class Method Details

.from_binary(plist) ⇒ Object



45
46
47
# File 'lib/plist4r/backend/c_f_property_list.rb', line 45

def from_binary plist
  from_string plist
end

.from_string(plist) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plist4r/backend/c_f_property_list.rb', line 18

def from_string plist
  cf_plist = CFPropertyList::List.new
  cf_plist.load_str(plist.from_string)
  ruby_object = CFPropertyList.native_types(cf_plist.value)

  hash_obj = nil
  if ruby_object.is_a? Hash
    hash_obj = ruby_object

  elsif ruby_object
    hash_obj = { ruby_object.class.to_s => ruby_object }

  else
    raise "Conversion tp plist object failed"
  end

  hash = ::Plist4r::OrderedHash.new
  hash.replace hash_obj
  plist.import_hash hash

  return plist
end

.from_xml(plist) ⇒ Object



41
42
43
# File 'lib/plist4r/backend/c_f_property_list.rb', line 41

def from_xml plist
  from_string plist
end

.to_binary(plist) ⇒ Object



55
56
57
58
59
# File 'lib/plist4r/backend/c_f_property_list.rb', line 55

def to_binary plist
  cf_plist = CFPropertyList::List.new
  cf_plist.value = CFPropertyList.guess(plist.to_hash)
  return cf_plist.to_str(CFPropertyList::List::FORMAT_BINARY)
end

.to_xml(plist) ⇒ Object



49
50
51
52
53
# File 'lib/plist4r/backend/c_f_property_list.rb', line 49

def to_xml plist
  cf_plist = CFPropertyList::List.new
  cf_plist.value = CFPropertyList.guess(plist.to_hash)
  return cf_plist.to_str(CFPropertyList::List::FORMAT_XML)
end