-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from TTRPG-Dev/qmalcolm--multiple-die-rolls
Enable `ex_ttrpg_dev roll` to handle multiple dice specs
- Loading branch information
Showing
3 changed files
with
31 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule ExTTRPGDev.CustomParsers do | ||
@moduledoc """ | ||
Custom parsers to be used with Optimus args :parse | ||
""" | ||
|
||
@doc """ | ||
Parses a string of dice specifications seperated by commas | ||
## Examples | ||
iex> ExTTRPGDev.CustomParsers.dice_parser("3d4, 1d10,2d20") | ||
{:ok, ["3d4", "1d10", "2d20"]} | ||
""" | ||
def dice_parser(arg) when is_bitstring(arg) do | ||
arg | ||
|> String.split(",") | ||
|> Enum.map(&String.trim(&1)) | ||
|> Kernel.then(fn result -> {:ok, result} end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule ExTTRPGDevTest.CustomParsers do | ||
use ExUnit.Case | ||
|
||
doctest ExTTRPGDev.CustomParsers | ||
end |