From 611da3afba588461a40c3a4fd25bbc3c702239a4 Mon Sep 17 00:00:00 2001 From: Raf Gemmail Date: Sun, 29 Oct 2017 11:27:49 +1300 Subject: [PATCH] Moved general knowledge to a yaml file --- lib/extreme_startup/general-knowledge.yaml | 14 ++++++++++++++ lib/extreme_startup/question_factory.rb | 14 ++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 lib/extreme_startup/general-knowledge.yaml diff --git a/lib/extreme_startup/general-knowledge.yaml b/lib/extreme_startup/general-knowledge.yaml new file mode 100644 index 0000000..0318c5c --- /dev/null +++ b/lib/extreme_startup/general-knowledge.yaml @@ -0,0 +1,14 @@ +--- +- + question: which year was Theresa May first elected as the Prime Minister of Great Britain + answer: 2016 +- + question: which city is the Eiffel tower in + answer: Paris +- + question: what colour is a banana + answer: yellow +- + question: who played James Bond in the film Dr No + answer: Sean Connery + diff --git a/lib/extreme_startup/question_factory.rb b/lib/extreme_startup/question_factory.rb index b15d41c..78c1431 100644 --- a/lib/extreme_startup/question_factory.rb +++ b/lib/extreme_startup/question_factory.rb @@ -315,20 +315,14 @@ def correct_answer class GeneralKnowledgeQuestion < Question class << self def question_bank - [ - ["in which year was Theresa May first elected as the Prime Minister of Great Britain", "2016"], - ["which city is the Eiffel tower in", "Paris"], - ["what currency did Spain use before the Euro", "peseta"], - ["what colour is a banana", "yellow"], - ["who played James Bond in the film Dr No", "Sean Connery"] - ] + return YAML.load_file(File.join(File.dirname(__FILE__), "general-knowledge.yaml")) end end def initialize(player) - question = GeneralKnowledgeQuestion.question_bank.sample - @question = question[0] - @correct_answer = question[1] + quiz_card = GeneralKnowledgeQuestion.question_bank.sample + @question = quiz_card["question"] + @correct_answer = quiz_card["answer"] end def as_text