First pass at uniformed types, specs and docs

- spec public functions (skipping controllers, views, live views and
components)
- use types instead of explanations in docs
- remove redundant docs
- fix typos
This commit is contained in:
Claudio Ortolina
2026-03-06 08:33:11 +00:00
parent 99e30d5fdf
commit 7cf9b4e7f8
81 changed files with 652 additions and 300 deletions
+13
View File
@@ -2,6 +2,16 @@ defmodule MusicBrainz.Artist do
@enforce_keys [:id, :name, :sort_name]
defstruct [:id, :name, :sort_name, :country, :relations, :musicbrainz_data]
@type t :: %__MODULE__{
id: String.t(),
name: String.t(),
sort_name: String.t(),
country: String.t() | nil,
relations: [map()] | nil,
musicbrainz_data: map() | nil
}
@spec from_api_response(map()) :: t()
def from_api_response(r) do
%__MODULE__{
id: r["id"],
@@ -15,6 +25,7 @@ defmodule MusicBrainz.Artist do
# MASSIVE ASSUMPTION: if there's more than one Discogs link,
# take the one with the lowest ID, as it's likely to be the main one.
@spec get_discogs_id(t()) :: integer() | nil
def get_discogs_id(r) do
candidates =
r.relations
@@ -32,6 +43,7 @@ defmodule MusicBrainz.Artist do
end
end
@spec get_wikidata_id(t()) :: String.t() | nil
def get_wikidata_id(r) do
Enum.find_value(r.relations, fn relation ->
if relation.type == "wikidata" do
@@ -40,6 +52,7 @@ defmodule MusicBrainz.Artist do
end)
end
@spec url(String.t()) :: String.t()
def url(id) do
"https://musicbrainz.org/artist/#{id}"
end