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
@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"
}
]
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"
}
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"]
Returns the generation of a device given its identifier e.g. iPhone13,1
Example
iex> IDeviceDb.id_to_generation("iPhone13,1")
"iPhone 12 mini"
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"]
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"]