Class: Xcselect::NKIssue

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/xcselect/nkissue.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_pathObject

Returns the value of attribute content_path.



13
14
15
# File 'lib/xcselect/nkissue.rb', line 13

def content_path
  @content_path
end

#dateObject

Returns the value of attribute date.



12
13
14
# File 'lib/xcselect/nkissue.rb', line 12

def date
  @date
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/xcselect/nkissue.rb', line 10

def name
  @name
end

#uuidObject

Returns the value of attribute uuid.



11
12
13
# File 'lib/xcselect/nkissue.rb', line 11

def uuid
  @uuid
end

Class Method Details

.archive_time_to_time(t) ⇒ Object

convert a date offset from 2001 to epoch



48
49
50
# File 'lib/xcselect/nkissue.rb', line 48

def self.archive_time_to_time t
  Time.at(t + NSTimeIntervalSince1970)
end

.find_class_key(hash) ⇒ Object



15
16
17
# File 'lib/xcselect/nkissue.rb', line 15

def self.find_class_key hash
  hash['$objects'].index(hash['$objects'].select{|o| o['$classname'] == "NKIssue"}.first)
end

.parse(file_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/xcselect/nkissue.rb', line 19

def self.parse file_name
  begin      
    ns_plist = Plist::parse_xml(read_bin_plist_to_xml(file_name))
    # this is the integer that we will use to filter all archived nkissue objects
    nk_issue_key =  find_class_key(ns_plist)

    # filter just the nkissue hashes
    object_array = ns_plist['$objects']
    obj_key_hashs = object_array.select{|o| o.class == Hash && o['$class'] && nk_issue_key == o['$class']['CF$UID'] }
  
    issues = {}
    obj_key_hashs.each do |nskey|
      issue = NKIssue.new
      issue.name = object_array[nskey['name']['CF$UID']]
      issue.uuid = object_array[nskey['directory']['CF$UID']]
      issue.date = self.archive_time_to_time(object_array[nskey['date']['CF$UID']]['NS.time'])
      issues[issue.name] = issue # unless name.nil?
    end
    return issues        
  rescue Exception => e
    return {}
  end
end

.read_bin_plist_to_xml(plist_path) ⇒ Object



52
53
54
# File 'lib/xcselect/nkissue.rb', line 52

def self.read_bin_plist_to_xml plist_path
  `plutil -convert xml1  -o - '#{plist_path}'`
end

Instance Method Details

#to_sObject



43
44
45
# File 'lib/xcselect/nkissue.rb', line 43

def to_s
  "<NKIssue:#{name}:#{date} #{uuid}>"
end