Sha256: 29ec64498e41c6f3a55c20464b153a4c18f6ab66438ab728f1faf450bdfa59f8
Contents?: true
Size: 1.36 KB
Versions: 8
Compression:
Stored size: 1.36 KB
Contents
require "triviacrack/game_statistics" require "triviacrack/parsers/category_statistics_parser" # Internal: This module is used to parse data returned from the Trivia Crack API # into a ruby object that represents player statistics for a Trivia Crack game. module TriviaCrack module Parsers module GameStatisticsParser # 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. 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 end end end
Version data entries
8 entries across 8 versions & 1 rubygems