View Source LibJudge.Rule (lib_judge v0.4.2)

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

Link to this section 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

Link to this section Types

Specs

rule_type() :: :category | :subcategory | :rule | :subrule

Specs

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

Link to this section Functions

Specs

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}
  ]
}

Specs

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"}}

Specs

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."}

Specs

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"