Class: XcodeprojUtils::Project
- Inherits:
-
Object
- Object
- XcodeprojUtils::Project
- Defined in:
- lib/xcodeproj_utils.rb
Instance Method Summary collapse
-
#initialize(proj_name, target_name) ⇒ Project
constructor
A new instance of Project.
- #search_unused_images ⇒ Object
- #show(kind, fullpath = false) ⇒ Object
- #wc(header_only = false, source_only = false) ⇒ Object
Constructor Details
#initialize(proj_name, target_name) ⇒ Project
Returns a new instance of Project.
6 7 8 9 10 11 |
# File 'lib/xcodeproj_utils.rb', line 6 def initialize(proj_name, target_name) @proj = Xcodeproj::Project::open(proj_name) @target = @proj.targets.select {|target| target.name == target_name} raise ArgumentError, "#{target_name} is not found in #{proj_name}" if @target.empty? @target = @target.first end |
Instance Method Details
#search_unused_images ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/xcodeproj_utils.rb', line 66 def search_unused_images sources = "" for file in @target.source_build_phase.files_references sources += File.read file.real_path end for file in @proj.files if file.path.end_with? ".h" sources += File.read file.real_path end end for file in @target.resources_build_phase.files_references type = file.last_known_file_type next unless type if type == 'file.xib' or type == 'text.plist.xml' sources += File.read file.real_path end end images = [] for file in @target.resources_build_phase.files_references type = file.last_known_file_type if not type or not type.match /^image/ next end name = File.basename(file.display_name, '.*') name = name.split('@').first.strip if name == 'Default' or name == 'Default-568h' next end if sources.scan(name).count == 0 images << file end end images.sort {|x,y| x.display_name <=> y.display_name} end |
#show(kind, fullpath = false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xcodeproj_utils.rb', line 45 def show(kind, fullpath=false) if kind == 'resource' files = @target.resources_build_phase.files_references elsif kind == 'source' files = @target.source_build_phase.files_references end if files for file in files next if file.class != Xcodeproj::Project::Object::PBXFileReference if fullpath puts file.real_path else puts file.path end end end return nil end |
#wc(header_only = false, source_only = false) ⇒ Object
13 14 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 40 41 42 43 |
# File 'lib/xcodeproj_utils.rb', line 13 def wc(header_only=false, source_only=false) all = !(header_only || source_only) # default is all count_source = lambda do sources = [] for file in @target.source_build_phase.files_references if file.last_known_file_type and file.last_known_file_type.include? "sourcecode" sources.push("'#{file.real_path}'") end end file_params = sources.join(' ') source_total = %x{wc -l #{file_params}} return source_total.lines[-1].split.first.to_i end count_header = lambda do headers = [] for file in @proj.files if file.path.end_with? ".h" headers.push("'#{file.real_path}'") end end file_params = headers.join(' ') header_total = %x{wc -l #{file_params}} return header_total.lines[-1].split.first.to_i end source_total = header_total = 0 source_total = count_source.call if all or source_only header_total = count_header.call if all or header_only source_total + header_total end |