View Source IDeviceDb (idevice_db v1.0.0)

A database of Apple devices.

This module provides a simple API for querying a database of Apple devices. The database is generated from the Apple Wiki and is stored in the priv directory.

When the module is loaded, the database is read from the priv directory and stored in persistent terms. This means that the database is only read from disk once and is then available in memory for the lifetime of the application.

The module provides two functions, generation_less_than?/2 and model_less_than?/2, which may be used as 'sorters' in the Enum.sort/2 function. These functions order by the age of the device, with the oldest devices first.

Summary

Functions

Returns a list of all devices in the database.

Finds a device by its model name e.g. MX132

Returns true if g1 is older than g2, false otherwise.

Returns the generation of a device given its identifier e.g. iPhone13,1

Returns true if i1 is older than i2, false otherwise

Returns true if m1 is older than m2, false otherwise

Functions

all_devices()

@spec all_devices() :: [map()]

Returns a list of all devices in the database.

Example

iex> IDeviceDb.all_devices |> Enum.take(1)
[
  %{
    finish: "Black",
    identifier: "iPhone1,1",
    generation: "iPhone",
    models: ["MA501"],
    internal_name: "M68AP",
    storage: "4 GB"
  }
]

find_by_model(model)

@spec find_by_model(String.t()) :: map() | nil

Finds a device by its model name e.g. MX132

Example

iex> IDeviceDb.find_by_model("MX132")
%{
  finish: "Space Gray",
  identifier: "iPhone10,1",
  generation: "iPhone 8",
  models: ["MX132"],
  internal_name: "D20AP",
  storage: "128 GB"
}

generation_less_than?(g1, g2)

@spec generation_less_than?(String.t(), String.t()) :: boolean()

Returns true if g1 is older than g2, false otherwise.

Intended to be used as a sorter in Enum.sort/2.

Example

iex> Enum.sort(["iPhone X", "iPhone 13 Pro Max", "iPhone 5c"], &IDeviceDb.generation_less_than?/2)
["iPhone 5c", "iPhone X", "iPhone 13 Pro Max"]

id_to_generation(identifier)

@spec id_to_generation(String.t()) :: String.t() | nil

Returns the generation of a device given its identifier e.g. iPhone13,1

Example

iex> IDeviceDb.id_to_generation("iPhone13,1")
"iPhone 12 mini"

identifier_less_than?(g1, g2)

@spec identifier_less_than?(String.t(), String.t()) :: boolean()

Returns true if i1 is older than i2, false otherwise

Intended to be used as a sorter in Enum.sort/2.

Example

iex> Enum.sort(["iPhone14,5", "iPhone12,8", "iPhone10,2"], &IDeviceDb.identifier_less_than?/2)
["iPhone10,2", "iPhone12,8", "iPhone14,5"]

model_less_than?(m1, m2)

@spec model_less_than?(String.t(), String.t()) :: boolean()

Returns true if m1 is older than m2, false otherwise

Intended to be used as a sorter in Enum.sort/2. Note that more than one model can map to a specific device. When comparing such models, this function will return false regardless of the order of the arguments.

Example

iex> Enum.sort(["MU163", "MYD13", "MQ9X3"], &IDeviceDb.model_less_than?/2)
["MQ9X3", "MU163", "MYD13"]