module TriviaCrack::Parsers::GameStatisticsParser

Public Class Methods

parse(raw_data) click to toggle source

Internal: Parses data returned from the Trivia Crack API to create a TriviaCrack::GameStatistics object.

raw_data - A hash of the raw data returned by the Trivia Crack API.

Examples

raw_data = get_raw_data_from_API
...
stats = TriviaCrack::Parsers::GameStatisticsParser.parse raw_data

Returns a TriviaCrack::GameStatistics.

# File lib/triviacrack/parsers/game_statistics_parser.rb, line 22
def self.parse(raw_data)
  categories =
    CategoryStatisticsParser.parse raw_data["category_questions"]

  if raw_data["crowns"]
    crowns = raw_data["crowns"].map { |c| c.downcase.to_sym }
  else
    crowns = []
  end

  TriviaCrack::GameStatistics.new(
    correct_answers: raw_data["correct_answers"],
    incorrect_answers: raw_data["incorrect_answers"],
    questions_answered: raw_data["questions_answered"],
    challenges_won: raw_data["challenges_won"],
    crowns: crowns,
    categories: categories
  )
end