Class: XcodeResultBundleProcessor::ElementSnapshot

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/xcoderesultbundleprocessor/element_snapshot.rb

Instance Method Summary collapse

Constructor Details

#initialize(plist) ⇒ ElementSnapshot

Returns a new instance of ElementSnapshot.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/xcoderesultbundleprocessor/element_snapshot.rb', line 3

def initialize(plist)
  super()

  @objects = plist.value.value['$objects'].value

  root_object = plist.value.value['$top'].value['root']

  self._deserialize_object(root_object).each do |key, value|
    self[key] = value
  end
end

Instance Method Details

#_deserialize_dictionary(cfdictionary) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xcoderesultbundleprocessor/element_snapshot.rb', line 15

def _deserialize_dictionary(cfdictionary)
  if cfdictionary.value.key?('NS.rectval')
    return self._deserialize_object(cfdictionary.value['NS.rectval'])
  end

  if cfdictionary.value.key?('$classname')
    return cfdictionary.value['$classname'].value
  end

  ret = {}
  if cfdictionary.value.key?('NS.keys') && cfdictionary.value.key?('NS.objects')
    keys_and_values = cfdictionary.value['NS.keys'].value.zip(cfdictionary.value['NS.objects'].value)
    keys_and_values.each do |key, value|
      ret[self._deserialize_object(key).to_s.to_sym] = self._deserialize_object(value)
    end
  elsif cfdictionary.value.key?('NS.objects')
    return cfdictionary.value['NS.objects'].value.map { |o| self._deserialize_object(o) }
  else
    cfdictionary.value.each do |key, value|
      ret[key.to_sym] = self._deserialize_object(value)
    end

  end
  ret
end

#_deserialize_object(object) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/xcoderesultbundleprocessor/element_snapshot.rb', line 41

def _deserialize_object(object)
  if object.is_a?(CFPropertyList::CFUid)
    self._deserialize_object(@objects[object.value])
  elsif object.is_a?(CFPropertyList::CFString) && object.value == '$null'
    nil
  elsif object.is_a?(CFPropertyList::CFDictionary)
    self._deserialize_dictionary(object)
  elsif object.is_a?(CFPropertyList::CFString) or object.is_a?(CFPropertyList::CFInteger) or object.is_a?(CFPropertyList::CFBoolean)
    object.value
  elsif object.is_a?(CFPropertyList::CFArray)
    object.value.map { |o| self._deserialize_object(o) }
  else
    raise "Unsupported object type #{object.class}"
  end
end

#_deserialize_uid(uid) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/xcoderesultbundleprocessor/element_snapshot.rb', line 57

def _deserialize_uid(uid)
  object = @objects[uid.value]

  if object.is_a?(CFPropertyList::CFUid)
    _deserialize_uid(uid)
  elsif object.is_a?(CFPropertyList::CFString) && object.value == '$null'
    nil
  elsif object.is_a?(CFPropertyList::CFDictionary)
    hash = {}

    object.value.each do |key, value|
      if value.is_a?(CFPropertyList::CFUid)
        hash[key] = self._deserialize_uid(value)
      else
        hash[key] = value.value
      end
    end

    hash
  else
    object.value
  end
end