Sha256: fe9541e2e33934b9cbba41c4509ba7a933d418ae71b7e292fe1431695f221462
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true 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) # rubocop:disable Metrics/MethodLength categories = CategoryStatisticsParser.parse raw_data['category_questions'] crowns = if raw_data['crowns'] raw_data['crowns'].map { |c| c.downcase.to_sym } else [] 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
triviacrack-0.8.0 | lib/triviacrack/parsers/game_statistics_parser.rb |
triviacrack-0.7.0 | lib/triviacrack/parsers/game_statistics_parser.rb |