Class: Antenna::IPA

Inherits:
Object
  • Object
show all
Defined in:
lib/antenna/ipa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ IPA

Returns a new instance of IPA.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/antenna/ipa.rb', line 9

def initialize(filename)
  @filename = filename
  @bundle_icon_files = {}

  Zip::File.open(filename) do |zipfile|
    # Determine app name
    @app_name = zipfile.dir.entries('Payload').
      select { |file| file =~ /.app$/ }.
      first
    raise "Unable to determine app name from #{filename}" unless @app_name

    # Find and read Info.plist
    infoplist_entry = zipfile.get_entry("Payload/#{@app_name}/Info.plist")
    infoplist_data = infoplist_entry.get_input_stream.read
    @info_plist = Antenna::InfoPlist.new(infoplist_data)
    raise "Unable to find Info.plist in #{filename}" unless @info_plist
  end
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/antenna/ipa.rb', line 7

def app_name
  @app_name
end

#bundle_icon_filesObject

Returns the value of attribute bundle_icon_files.



7
8
9
# File 'lib/antenna/ipa.rb', line 7

def bundle_icon_files
  @bundle_icon_files
end

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/antenna/ipa.rb', line 7

def filename
  @filename
end

#info_plistObject

Returns the value of attribute info_plist.



7
8
9
# File 'lib/antenna/ipa.rb', line 7

def info_plist
  @info_plist
end

Instance Method Details

#bundle_icon(size, resolution = 1) ⇒ Object

Returns icon image data for given pixel size and resolution (defaults to 1).



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/antenna/ipa.rb', line 29

def bundle_icon(size, resolution=1)
  icon_data = nil
  if resolutions = @info_plist.bundle_icons[size]
    if filename = resolutions[resolution]
      icon_glob = "Payload/#{@app_name}/#{filename}*.png"
      Zip::File.open(@filename) do |zipfile|
        zipfile.glob(icon_glob).each do |icon|
          icon_data = icon.get_input_stream.read
        end
      end
    end
  end
  icon_data
end

#input_streamObject



44
45
46
# File 'lib/antenna/ipa.rb', line 44

def input_stream
  File.open(@filename, "r")
end