class Antenna::InfoPlist

Attributes

bundle_display_name[RW]
bundle_icons[RW]
bundle_identifier[RW]
bundle_minimum_os_version[RW]
bundle_short_version[RW]
bundle_version[RW]

Public Class Methods

determine_icons(iconfiles) click to toggle source

Heuristically determines available icon sizes and resolutions from icon filenames and normalizes them into a hash. This hopefully works for most cases out there. Returns a hash of hashes like the following: { icon_width => { icon_resolution => icon_filename } }

# File lib/antenna/infoplist.rb, line 17
def determine_icons(iconfiles)
  icons = Hash.new { |h, k| h[k] = { } }
  iconfiles.each { |file| 
    (width, height, resolution) = file.to_s.scan(/(\d+)?x?(\d+)?@?(\d+)?x?(\.png)?$/).flatten
    next unless width
    icons[width.to_i][(resolution || 1).to_i] = File.basename(file, ".*")
  }
  icons
end
from_file(filename) click to toggle source

Class method to instantiate object with data from file.

# File lib/antenna/infoplist.rb, line 9
def from_file(filename)
  self.new(File.read(filename))
end
new(data) click to toggle source
# File lib/antenna/infoplist.rb, line 28
def initialize(data)
  infoplist = CFPropertyList::List.new(:data => data)
  infoplist_data = CFPropertyList.native_types(infoplist.value)

  @bundle_display_name        = infoplist_data["CFBundleDisplayName"] || infoplist_data["CFBundleName"]
  @bundle_identifier          = infoplist_data["CFBundleIdentifier"]
  @bundle_short_version       = infoplist_data["CFBundleShortVersionString"]
  @bundle_version             = infoplist_data["CFBundleVersion"]
  @bundle_minimum_os_version  = infoplist_data["MinimumOSVersion"]
  @bundle_icons               = {}

  if icons = infoplist_data["CFBundleIconFiles"]
    @bundle_icons = self.class.determine_icons(icons)
  else
    if icons = infoplist_data["CFBundleIcons"]
      if primary_icon = icons["CFBundlePrimaryIcon"]
        @bundle_icons = self.class.determine_icons(primary_icon["CFBundleIconFiles"])
      end
    end
  end
end