hedwig_trivia v0.1.0 HedwigTrivia.Question View Source

Logic surrounding fetching and evaluating questions from the API

Link to this section Summary

Functions

Returns :ok if the the question is not obviously unanswerable, since the API sometimes returns that.

Call the API to fetch a new question, verify it's playable, and add the data to the game state.

Strip HTML tags from answers. There are definitely better ways to do this, but I'm being very lazy.

Link to this section Functions

Link to this function

check_worthiness(res)

View Source
check_worthiness(map()) :: :ok | :error

Returns :ok if the the question is not obviously unanswerable, since the API sometimes returns that.

Examples

iex> Question.check_worthiness(%{"question" => "asdf", "answer" => "asdf"}) :ok

iex> Question.check_worthiness(%{"question" => "=", "answer" => "asdf"}) :bad

iex> Question.check_worthiness(%{"question" => "=", "answer" => "asdf"}) :bad

Link to this function

fetch(state, api \\ API)

View Source

Call the API to fetch a new question, verify it's playable, and add the data to the game state.

Link to this function

strip_html(raw_answer)

View Source
strip_html(String.t()) :: String.t()

Strip HTML tags from answers. There are definitely better ways to do this, but I'm being very lazy.