Sha256: db2985b95e117dfa9b283417982f8f2d94ce6e502acae7a1ee4ccac8f1bc2c8f

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

require "triviacrack/question"

# Internal: This module is used to parse data returned from the Trivia Crack API
# into a ruby object that represents a Trivia Crack question.
module TriviaCrack
  module Parsers
    module QuestionParser

      # Internal: Parses data returned from the Trivia Crack API to create a
      # TriviaCrack::Question object.
      #
      # raw_data  - A hash of the raw data returned by the Trivia Crack API.
      #
      # Examples
      #
      #   raw_data = get_raw_data_from_API
      #   ...
      #   question = TriviaCrack::Parsers::QuestionParser.parse raw_data
      #
      # Returns a TriviaCrack::Question.
      def self.parse(raw_data)
        TriviaCrack::Question.new(
          id: raw_data["id"],
          type: raw_data["type"].downcase.to_sym,
          category: raw_data["category"].downcase.to_sym,
          text: raw_data["text"],
          answers: raw_data["answers"],
          correct_answer: raw_data["correct_answer"],
          media_type: raw_data["media_type"].downcase.to_sym,
          image_url: raw_data["base_url"]
        )
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
triviacrack-0.6.0 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.5.1 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.5.0 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.4.0 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.3.2 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.3.0 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.2.0 lib/triviacrack/parsers/question_parser.rb
triviacrack-0.1.0 lib/triviacrack/parsers/question_parser.rb