defmodule Runbox.Scenario.Asset do
@moduledoc group: :utilities
@moduledoc """
Utilities for working with Asset
"""
@spec split_id(String.t()) :: {String.t(), String.t()}
@doc """
Split asset id by the last slash.
## Example
iex> Asset.split_id("/type/id")
{"/type", "id"}
iex> Asset.split_id("id")
{"", "id"}
"""
def split_id(asset_id) do
case Regex.split(~r/\/[^\/]+$/, asset_id, include_captures: true) do
[type, "/" <> id, ""] ->
{type, id}
_ ->
# only ID without type (no slash /)
{"", asset_id}
end
end
end