Class: Xcselect::XcApp

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ XcApp

Returns a new instance of XcApp.



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

def initialize(path)
  @path = path
  @info_plist = JSON.parse read_plist(plist_path)
end

Instance Attribute Details

#info_plistObject (readonly)

Returns the value of attribute info_plist.



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

def info_plist
  @info_plist
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.all_appsObject

all applications for all simulator versions, unsorted



116
117
118
# File 'lib/xcselect/xcapp.rb', line 116

def self.all_apps
  Dir["#{app_support_folder}/**/*.app"].map{|a| XcApp.new a }
end

.all_newsstand_appsObject

every newsstand application



121
122
123
# File 'lib/xcselect/xcapp.rb', line 121

def self.all_newsstand_apps
  self.all_apps.select(&:newsstand?)
end

.app_support_folderObject

the iPhone Simulator support folder



111
112
113
# File 'lib/xcselect/xcapp.rb', line 111

def self.app_support_folder
  File.expand_path("~/Library/Application Support/iPhone Simulator/")
end

.last_built_appObject



133
134
135
# File 'lib/xcselect/xcapp.rb', line 133

def self.last_built_app
  XcApp.sort_by_touch_time(all_apps).last
end

.last_built_newsstand_appObject



125
126
127
# File 'lib/xcselect/xcapp.rb', line 125

def self.last_built_newsstand_app
  all_newsstand_apps.sort_by{|e| e.last_build_time }.last
end

.sort_by_touch_time(array) ⇒ Object



129
130
131
# File 'lib/xcselect/xcapp.rb', line 129

def self.sort_by_touch_time array
  array.sort_by{|e| e.last_build_time }
end

Instance Method Details

#<=>(o) ⇒ Object



22
23
24
25
# File 'lib/xcselect/xcapp.rb', line 22

def <=>(o)
  result = sim_version.to_f <=> o.sim_version.to_f 
  (!result.zero?) ? result : name <=> o.name
end

#[](k) ⇒ Object



31
32
33
# File 'lib/xcselect/xcapp.rb', line 31

def [](k)
  @info_plist[k]
end

#base_dirObject



35
36
37
# File 'lib/xcselect/xcapp.rb', line 35

def base_dir
  File.dirname path
end

#bundle_idObject



39
40
41
# File 'lib/xcselect/xcapp.rb', line 39

def bundle_id
  self['CFBundleIdentifier']
end

#cache_pathObject



63
64
65
# File 'lib/xcselect/xcapp.rb', line 63

def cache_path
  "#{base_dir}/Library/Caches"
end

#documents_pathObject



59
60
61
# File 'lib/xcselect/xcapp.rb', line 59

def documents_path
  "#{base_dir}/Documents"
end

#last_build_timeObject



104
105
106
# File 'lib/xcselect/xcapp.rb', line 104

def last_build_time
  File.mtime path
end

#nameObject



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

def name
  self['CFBundleName']
end

#newsstand?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/xcselect/xcapp.rb', line 71

def newsstand?
  self['UINewsstandApp'] || false
end

#newsstand_issue_pathsObject

all directories in newsstand folder



95
96
97
98
99
100
101
102
# File 'lib/xcselect/xcapp.rb', line 95

def newsstand_issue_paths
  #TODO: make this read the newsstand db and return a hash of names/paths
  if oomph_app? 
    Dir["#{newsstand_path}/*-*/*"]         
  else
    Dir["#{newsstand_path}/*-*"]
  end
end

#newsstand_objectsObject

Returns a hash of NKIssues in the form {“issue_name” => path }



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xcselect/xcapp.rb', line 76

def newsstand_objects
  issues = NKIssue.parse "#{base_dir}/Library/Application Support/com.apple.newsstand-library.plist"

  return issues unless newsstand?
  paths = newsstand_issue_paths if oomph_app?      
  issues.values.each do |issue|
    issue.content_path = "#{newsstand_path}/#{issue.uuid}"
    issue.content_path = paths.select{|p| p[issue.uuid] }.last if oomph_app?
  end

  return issues
end

#newsstand_pathObject

path to the app’s root newsstand folder



90
91
92
# File 'lib/xcselect/xcapp.rb', line 90

def newsstand_path
  "#{base_dir}/Library/Caches/Newsstand"
end

#oomph_app?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/xcselect/xcapp.rb', line 67

def oomph_app?
  File.exists? "#{path}/Oomph.plist"
end

#plist_pathObject



55
56
57
# File 'lib/xcselect/xcapp.rb', line 55

def plist_path
  Dir[@path + "/*Info.plist"].first
end

#read_bin_plist_to_xml(plist_path) ⇒ Object



51
52
53
# File 'lib/xcselect/xcapp.rb', line 51

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

#read_plist(plist_path) ⇒ Object



47
48
49
# File 'lib/xcselect/xcapp.rb', line 47

def read_plist plist_path
  `plutil -convert json  -o - '#{plist_path}'`
end

#sim_versionObject



27
28
29
# File 'lib/xcselect/xcapp.rb', line 27

def sim_version
  path.split('/')[-4]
end

#to_sObject



18
19
20
# File 'lib/xcselect/xcapp.rb', line 18

def to_s
  "#{name} (#{sim_version})"
end