View Source LibJudge.Rule (lib_judge v0.4.8)

Defines the Rule structure and provides methods for generating and working with them

Summary

Functions

Creates a list of Rules referenced in a string

Creates a Rule struct from a string

Turns a Rule back into a string

Turns a Rule back into a string

Types

@type rule_type() :: :category | :subcategory | :rule | :subrule
@type t() :: %LibJudge.Rule{
  category: String.t(),
  rule: String.t(),
  subcategory: String.t(),
  subrule: String.t(),
  type: rule_type()
}

Functions

@spec all_from_string(String.t()) :: {:ok, [t()]} | {:error, String.t()}

Creates a list of Rules referenced in a string

Examples

iex> LibJudge.Rule.all_from_string("See rules 702.21j and 702.108.")
{
  :ok,
  [
    %LibJudge.Rule{type: :subrule, category: "7", subcategory: "02", rule: "21", subrule: "j"},
    %LibJudge.Rule{type: :rule, category: "7", subcategory: "02", rule: "108", subrule: nil}
  ]
}
@spec from_string(String.t()) :: {:ok, t()} | {:error, String.t()}

Creates a Rule struct from a string

Examples

iex> LibJudge.Rule.from_string("702.21j")
{:ok, %LibJudge.Rule{type: :subrule, category: "7", subcategory: "02", rule: "21", subrule: "j"}}
@spec to_string(t()) :: {:ok, String.t()} | {:error, reason :: any()}

Turns a Rule back into a string

Non-bang variant

Examples

iex> LibJudge.Rule.to_string(%LibJudge.Rule{type: :category, category: "1"})
{:ok, "1."}
@spec to_string!(t()) :: String.t() | no_return()

Turns a Rule back into a string

Examples

iex> LibJudge.Rule.to_string!(%LibJudge.Rule{type: :subrule, category: "7", subcategory: "02", rule: "21", subrule: "j"})
"702.21j"